Tuesday, December 23, 2014

Bash Dynamic Brace Expansion w/Eval & w/o * files -- shopt -s nullglob

If you don't turn the Bash shell option nullglob on you will get *'s for the extensions you want to process.
$BRACES="{jp3g,jp4eg,g2if}"  
$ for a in $(eval "echo *${BRACES}"); do echo $a; done
*jp3g *jp4eg *g2if
$ shopt -s nullglob
$ for a in $(eval "echo *${BRACES}"); do echo $a; done
$
Voila, no more expansion to non-existent file names!

No comments:

Post a Comment