[ale] Undesired shell expansion building a command line

Michael B. Trausch mbt at zest.trausch.us
Wed Aug 26 15:56:47 EDT 2009


On Wed, 2009-08-26 at 13:47 -0600, JK wrote:
> Michael B. Trausch 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=""
> > for ARG in $EXCLUDED; do
> >     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 *~
> > 
> 
> Try:
> 
>    # Turn pathname expansion off (temporarily).
>    set -f
>    EXCLUDED="${EXCLUDED} /lib /usr/lib *~"
>    # And assuming you want to turn pathname expansion back on:
>    set +f

Hah, that worked.  I also had to wrap a line later with that pair to
prevent one more expansion of it, as well.

I hadn't thought to look through the shell's list of set options, I was
searching for "glob" in the man page and didn't come across that.  Of
course, that's because in that instance they said "filename expansion"
and not "filename globbing".  Heh.  Oops.

	--- Mike


More information about the Ale mailing list