Check if file exist inside tar file using tar and grep command
10,169
Because some_file
is inside the tarfile.tar
file but your if
is checking for it to be on the file system.
You can alter it like this
if tar –tf tarfile.tar some_file >/dev/null 2>&1; then
echo "tarfile.tar contains some_file"
fi
Author by
Erin Santos
Updated on June 11, 2022Comments
-
Erin Santos almost 2 years
I have a script that check if a file exist inside a tar file but something's wrong because it always go to the 'else' part of the script. I am pretty sure that it shouldn't be that way.
The date is in "Mon dd" format (Jan 11).
echo "enter date: \c" read date tarfile=`tar -tvf tarfile.tar | grep some_file | grep "$date"` if [ -f "$tarfile" ]; then echo "yes" else echo "no" fi
Thanks.