Menu

Dipesh Majumdar

Blog and Paintings

How to have OR in condition in an IF statement of a shell script

August 18, 2014

Showing below the if statement to illustrate this. The condition shown is just an example and has no meaning as such. In this same example you can also find a way to send an output from a script to an email id. This will be useful in those cases where you might want to configure a monitoring mechanism of a particular process. say when the process fails - it gives an output and you can take that output in an IF condition and configure an alert mechanism to your email id. Also in this same example it is also shown that if the entry in an echo needs to be broken into new lines you can use this with escape character (\n)

Note that the below condition to be interpreted like this -> if [1st condition OR 2ND condition]
That means -> If either first condition evaluates to true or 2nd evaluates to true, then the statement after IF condition will be implemented. 

if [ "$VARIABLE1" == "$VARIABLE2" -o "$VARIABLE3" == "1" ]; then

echo -e "ABCDEFGHI... \n---------------------------------------------------\n$VARIABLE1 " | mail -s "so and so HEALTH REPORT" dipesh.majumdar@gmail.com

 

echo "=============================================|"
echo "ABCDEFGHI BLA BLAH...........................|"


else

echo "=============================================|"
echo "something else...............................|"

fi

Go Back

Comment