Software >> OS >> Unix >> Linux >> Shell >> Scripting >> How to test whether a file or directory 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 [ -d /etc/sysconfig ] then ls /etc/sysconfig fi example 3 --------- #! /bin/bash if test -f /etc/sysconfig/httpd then ./etc/sysconfig/httpd fi