13 February 2012

Logical Operators in Shell Scripts

Leave a Comment

Here are Logical operators that are used during Shell Script.

OPERATOR DESCRIPTION
cond1 -a cond2 True if cond1 and cond2 are True(Performs AND operation)
cond1 -o cond2 True if con1 or cond2 is True (Perform OR operation)
!cond1 True if cond1 is false

Example


$ cat > rop.sh
#!/bin/bash
a=25
b=29

if [ $a -gt 20 -a $b -gt 25 ] ; then
echo "both condition stisfied"
fi

if [ $a -gt 25 -o $b -gt 25 ] ; then
echo "only one condition is satisfied"
fi

Output


That's it.
Enjoy :)


If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

0 comments:

Post a Comment