[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Mapfile callback access to current line
From: |
Chet Ramey |
Subject: |
Re: Mapfile callback access to current line |
Date: |
Sat, 15 Jan 2011 11:53:09 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.8) Gecko/20100802 Lightning/1.0b2 Thunderbird/3.1.2 |
On 1/15/11 12:28 AM, Chris F.A. Johnson wrote:
> 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).
Too belated, it seems. Bash-4.2 passes the line read and to be assigned
to the array element as the second argument to the callback function.
That means that
mapfile -C "echo" -c 1 -t A
numbers the input lines like `cat -n', but starting from 0, and leaves the
result in A.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/