I am trying to test if the tar file I am about to create already exists. If it doesn't then I want to create the tar file (this part of the code works). However the if statement testing if that file name for the tar file exists, doesn't work (doesn't actually test if the tar file exists, just skips straight to the else statement even if the tar file does already exist). Any ideas?
Note: fire_dir_name is the name of the file we are trying to tar ie.) myfile1.txt
#create variable for new name of file/dir date=$(date +"%Y%m%d") new_name="$file_dir_name.$date" file_name="$new_name.tar" echo $file_name #check if tar file exists already if [ -f "$file_name" ] then echo "$file_name" exists else # create tar file tar -cvf $dir_path/$new_name.tar $file_dir_name -C $dir_path