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: \cread datetarfile=`tar -tvf tarfile.tar | grep some_file | grep $date`if [ -f $tarfile ]; then    echo yes    else    echo nofi
tar and if-statement
files;scripting;ksh;tar
You're checking if the file exists by using -f, but that's not what you want to do. The file exists in the tar file, but -f has no way of reading inside tar archives by itself. For example, if your file is at foo/bar inside the tar file, it will look for foo/bar relative your current directory, which doesn't exist.The better way is to just check the exit status of grep, instead of trying to parse the output.printf 'enter date: 'read dateif tar -tvf tarfile.tar | grep some_file | grep -q $date; then    echo yeselse    echo nofi