Exit status codes are used to terminate the script with the exit command. The exit command can be passed an integer value of the exit code to return from the script to the shell.
if [ -a $FILENAME]
if [ $? eq 1 ]
echo "Couldn't find required file"
In this example we wrote two scripts. Script1 simply checks for the existance of a file and if the file is found exits with exit code 0 and if the file is not found exits with exit code 1. Script2 checks the exit code which is stored in $?. If exit code 1 was returned the script echos that the file couldn't be found and exits with exit code 1.
Case statements work much like if statements except case statement can only interpret one statement against multiple conditions. Case statements are closed with esac or case backwards.
case $ARGV in
echo "Who knows"
In this example the variable $ARGV (first command line option) is processed with a case statement. If "scriptname country" is executed USA is echoed back. If "scriptname state" is run Texas is echoed back. Anything else entered after the script name Who Knows is echoed back to the terminal.