[ale] Undesired shell expansion building a command line

Björn Gustafsson bg-ale at bjorng.net
Wed Aug 26 15:50:59 EDT 2009


On Wed, Aug 26, 2009 at 3:30 PM, Michael B. Trausch<mbt at zest.trausch.us> wrote:
> I have the following in a shell script:
>
> EXCLUDED="/dev /sys /proc /tmp /bin /usr/bin /usr/sbin /sbin"
> EXCLUDED="${EXCLUDED} /lib /usr/lib *~"
>
> EXCLUDE_ARGS=""
set -f # it's the "in $EXCLUDED" that is doing globbing.
> for ARG in $EXCLUDED; do
set +f
>    EXCLUDE_ARGS="${EXCLUDE_ARGS} --exclude ${ARG}"
> done
>
> The end result that I expect is to build the following:
>
> --exclude /dev --exclude /sys --exclude /proc --exclude /tmp
> --exclude /bin --exclude /usr/bin --exclude /usr/sbin --exclude /sbin
> --exclude /lib --exclude /usr/lib --exclude *~
>
> But, when each item in $EXCLUDED is evaluated to become $ARG, it appears
> to undergo filename expansion.  If no files fitting the pattern '*~'
> exist in the current directory, it evaluates fine.  On the other hand,
> if there are files matching '*~', it expands to those filenames.  I'd
> like to suppress globbing while building that so that it works always,
> but I actually don't know where to look on how.  It seems that there
> isn't a way around the expansion while evaluating the loop.
>
> I hope I'm wrong.  Am I?
>
>        --- Mike

-- 
Björn Gustafsson



More information about the Ale mailing list