bug-bash
[Top][All Lists]
Advanced

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

Re: Another mapfile question.


From: Maarten Billemont
Subject: Re: Another mapfile question.
Date: Fri, 5 Aug 2011 15:08:00 +0200

> IFS=
> aa=()
> while read line
> do
>  aa+=("$line")
> done < fn

You should really put that IFS= on your 'read', so as not to break the default 
wordsplitting for the rest of your script:

while IFS= read -r line

> vs.
> IFS=$'\n'
> aa=($(< fn))

Don't leave expansions unquoted!  you're still permitting pathname expansion 
here.

IFS=$'\n' read -rd '' -a aa < <(fn)

> vs.
> mapfile -t aa < fn

When compared to the above read, this will also read empty lines.  The read 
operation will merge multiple newlines into a single delimiter (as it does for 
all types of whitespace in IFS).

The while read works fine but is verbose.  The mapfile is a bit more concise.  
The read -a is fine and concise so long as you can live with the lack of empty 
lines.  I doubt mapfile is much use to you that while read doesn't already give 
you.

Attachment: smime.p7s
Description: S/MIME cryptographic signature


reply via email to

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