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