I was trying to use unquoted strings expansions to pass two arguments to tar; the first is the command-line flag --exclude
and the second contains a *
character. In an attempt to avoid premature globbing, I tried quoting the *
:
shopt -s nullglob
x="--exclude '*'"
echo tar $x
To my surprise, the '*'
completely disappeared! Here was the output:
tar --exclude
I understand that I could switch from POSIX shell to Bash and use arrays to avoid this headache. But I still wonder: what the hell was going on with that POSIX shell snippet? Why did it delete the quoted globs? I would have expected that it would leave the quoted part alone, or go all the way and expand the glob. It did neither of those.