I am trying to make script which will check if file exists. Filename is passed by argument. The script is checking if file exists in current directory.
#!/bin/bash tmp=$(find $1) failure="find: ‘$1‘: No such file or directory" if [ "$tmp" != "$failure" ]; then echo "file exists" else echo "file not exists" fi I am creating two variables. First one holds result of find command, and the second one holds the failure message of find command. In if statement I am comparing those variables.
Even if file exists I am getting always else statement message. What is wrong with this code?
if [[ -e "$1" ]]; then echo "file exists"; else echo "file not exists"; fi?