List the names of existing directories from .tgz file in a bash variable
- by Tom
I would like to find all the directories that are in a .tgz file and that already exist on the system and put the result in a bash variable.
I have tried this:
EXISTING=`for f in \`tar tzf $ARCHIVE\`; do if [ -d "/tmp/unpacked-data/\$f" ]; then echo \$f; fi; done`
with no luck. If I echo the value of $f before the if in the loop, I get all the files, ie this works:
EXISTING=`for f in \`tar tzf $ARCHIVE\`; do echo \$f; done`
Can someone tell me why the \$f doesn't work in the if statement?
Thanks,
Tom