Software >> OS >> Unix >> Linux >> Shell >> Scripting >> How to test whether a file exists in a shell script

BASH ==== for file use "if [ -f ..." for dir use "if [ -d ..." example 1 --------- #! /bin/bash if [ -f /etc/sysconfig/httpd ]; then ./etc/sysconfig/httpd fi example 2 --------- #! /bin/bash if [ -f /etc/sysconfig/httpd ] then ./etc/sysconfig/httpd fi example 3 --------- #! /bin/bash if test -f /etc/sysconfig/httpd then ./etc/sysconfig/httpd fi