we can use [ -f file.name ] ,this shell to check whether exists or not. however we should take a close look at the writting format. there should be must a space between bracket [ ], if there is a space ,there will be a error。so be careful with these common usage。
you also can use as follows for a shell prompt :[ -f /tmp/foo.txt ] && echo "File Exists" || echo "File not found"
#!/bin/bash file=$1 [ $# -eq 0 ] && { echo "Usage: $0 filename"; exit 999; } if [ -f $file ]; then echo "File $file exists." else echo "File $file does NOT exists." fiRun it as follows:
$ ./script.sh /etc/resolv.conf