List the names of existing directories from .tgz file in a bash variable
Posted
by Tom
on Stack Overflow
See other posts from Stack Overflow
or by Tom
Published on 2010-05-14T05:27:56Z
Indexed on
2010/05/14
5:34 UTC
Read the original article
Hit count: 320
bash
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
© Stack Overflow or respective owner