I have a problem with the following ksh script:
#! /usr/bin/ksh
EXCLUDE+=" --exclude '/bin/a*' "
echo $EXCLUDE
tar --preserve-permissions --create $EXCLUDE --file tar.tar /bin
Since passing in a pattern to the exclude target need single quotes around it. (I want to exclude all files in /bin folder beginning with “a”).
The Echo line also show the correct and unchanged result (the pattern didn’t expand and the single quote is still there). However this exclude target has no effect.
But if I put the actual value instead of $EXCLUDE, it worked!
#! /usr/bin/ksh
tar --preserve-permissions --create --exclude '/bin/a*' --file tar.tar /bin
It must be some quoting issue I’m encountering, but what?
EXCLUDE=' --exclude /bin/a* 'is enough.Your code excludes the
'/bin/a*'(quotes''are part of pattern) pattern but what you actually want is to exclude/bin/a*pattern.