[LEDE-DEV] [patch master 01/15] Double quote to prevent globbing and word splitting

Oswald Buddenhagen oswald.buddenhagen at gmx.de
Sat Oct 1 00:35:47 PDT 2016


On Fri, Sep 30, 2016 at 11:50:09PM +0200, Lars Kruse wrote:
> Am Fri, 30 Sep 2016 22:02:15 +0200 schrieb Jan-Tarek Butt <tarek at ring0.de>:
> > -		for pattern in $(eval echo $spec); do
> > -			find $libdirs -name "$pattern.so*" | sort -u
> > +		for pattern in $(eval echo "$spec"); do
> > +			find "$libdirs" -name "$pattern.so*" | sort -u
> 
> Just out of curiosity: do you know, what could be the purpose of the "eval"
> construct above?
> I would assume that:
>  for pattern in $spec; do
> behaves exactly like:
>  for pattern in $(eval echo $spec); do
> 
nope. $spec may contain brace expansions, which would not be processed
without the eval. (note that regular file globs *are* processed even
without it).

whether quotes are added here or not doesn't matter at all, because
eval sees all arguments as a single string anyway - if you wanted to
quote/escape anything, the string itself would have to contain the
quotes/backslashes. so if it's about good style, this should be written
as eval "echo $spec".

fwiw, i also used $(eval echo $foo) for whitespace normalization before.
ugly, but short and effective.




More information about the Lede-dev mailing list