bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mapfile callback access to current line


From: Chris F.A. Johnson
Subject: Re: Mapfile callback access to current line
Date: Sat, 15 Jan 2011 00:28:40 -0500 (EST)
User-agent: Alpine 2.00 (LMD 1167 2008-08-23)

On Mon, 17 May 2010, Chet Ramey wrote:

On 4/15/10 11:56 PM, DennisW wrote:
Mapfile would be that much more powerful if the callback function had
access to the current line. Is there any chance this might be added in
the future?

Sure, there's a chance.  What would be the most useful form?  A shell
variable that lives for the duration of the execution of the callback
function?

   [A somewhat belated reply!]

   It appears that the assignment is made after the function is called
   rather than before. I would like the value passed to the callback
   function to be the index of the line just read (and already
   assigned to the array).

   IOW, this script would print the file:

xx()
{
 printf "%3d %s\n" "$1" "${l[$1]}"
}

mapfile -c1 -C xx -t l < ~/.bashrc

   Now, "${l[$1]}" is empty; it would be great if it contained the line
   just read.

--
   Chris F.A. Johnson, <http://cfajohnson.com/>
   Author:
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]