[prev] [index] [next]

If Command (cont)

Examples:

# Check whether a file is readable

if [ -r $HOME ]     # neater than:  if test -r $HOME
then
   echo "$0: \$HOME is readable"
fi

# Test whether a user exists in passwd file

if grep "^$user" /etc/passwd > /dev/null
then
    ... do something if they do exist ...
else
   echo "$0: $user does not exist"
fi