bug-bash
[Top][All Lists]
Advanced

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

Re: Severe Bash Bug with Arrays


From: Maarten Billemont
Subject: Re: Severe Bash Bug with Arrays
Date: Thu, 26 Apr 2012 17:54:27 +0200

On 26 Apr 2012, at 01:18, Linda Walsh wrote:
> 
> Ishtar:> echo "${b[*]}"

Please note that expanding array elements using [*] is usually NOT what anyone 
wants.  Be careful about recommending it to anyone.

"${b[*]}" # This throws away any usefulness of the array by merging all the 
array elements into one single string (argument), concatenating the elements 
using the first character of IFS.
${b[*]} # Never do this.  On top of throwing away the usefulness of your array 
like above, you then follow up by re-splitting the whole thing using standard 
wordsplitting, not to mention pathname expanding the resulting words.

"${b[@]}" # Expands each array element as a separate argument, protecting it 
from wordsplitting and pathname expansion mutilation.
${b[@]} # Identical to and just as broken as ${b[*]}.  Never do this.

You should always recommend the "${b[@]}" variant.  "${b[*]}" is rarely useful 
in the event that your intent is to merge the array into a single string, eg. 
for displaying elements to a user:
dirs=(*/)
(IFS=,; echo "The dirs are: ${dirs[*]}")

But anyway, that's an aside from this topic, which has very little to do with 
this.

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


reply via email to

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