bug-bash
[Top][All Lists]
Advanced

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

Another mapfile question.


From: Steven W. Orr
Subject: Another mapfile question.
Date: Thu, 04 Aug 2011 09:38:37 -0400
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11

I never even noticed that mapfile exists. I read the section, I googled the
galaxy to look for example usage, and I am stuck as to why this is A Good Thing.

Is there an example of how to use this that uses the callback feature? And why is this preferable to using a while read loop? I'd just like to see why this is a useful thing.

I did find one comment from Chet: "It was requested and contributed by the bashdb folks. I suppose Rocky could weigh in on it."

Is using mapfile supposed to be faster than using something like:
IFS=
aa=()
while read line
do
   aa+=("$line")
done < fn
vs.
IFS=$'\n'
aa=($(< fn))
vs.
mapfile -t aa < fn

Also, I'm sort of stumped at the notion of the callback getting the index of the element that is about to be assigned, versus getting the text that was just read.

If I could just get a clue of why this is useful... I can see the usefulness of -t -n -s, but the value of the callback eludes me.

TIA

--
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net



reply via email to

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