Question : Exit Shell Script on Error

I am used to DOS scripting where you use the GOTO command to move around within the file. I am doing a shell script and ran into a slight little problem that I can't seem to resolve using Google. Here is what I have....

In my script I check for the existence of a file. If it doesn't exist, I want it to email me and than exit. However, I am not sure how to do that. Here is what I have so far:
1:
2:
3:
4:
5:
6:
7:
8:
9:
#!/bin/bash

if [ -e /opt/file/file.log ]
then 
	echo "file is there"
else
	#code to send email
	exit
fi

Answer : Exit Shell Script on Error

Hi,

you code is quite OK and correct!

The test "-e" will check for FILE EXISTS.
Besides that you could test for a regular file ("-f"), or excutable ("-x") and so on.
See "man test" for more.

wmp
Random Solutions  
 
programming4us programming4us