Back to the main page

Error handling

This subroutine can be places in oder scripts in order to handle errors. You can use it with different messages for different situations. Here is simple example.


#!/bin/sh	
#set -x	
	
# ***  Subroutines ***	
	
err() {	
        echo "\n ERROR: $* \n"	
        exit 1	
}	
	
# ***  End of Subroutines ***	
	
if [ -d /.1 ]	
	then	
        	echo "\n Directory /.1 exists"	
	else	
        	err "Dir /.1 is not here :( "	
fi	
	
if [ -f /reconfigure ]	
	then	
        	echo "\n File /reconfigure is present \n"	
	else	
        	err "\n Hey, I can't find the file .... "	
fi	
	
sleep 2	

echo "Will continue - thanks"	
	
exit 0	

Back to the main page