0% found this document useful (0 votes)
7 views

Operators

Uploaded by

Himani Verma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Operators

Uploaded by

Himani Verma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

https://www.codepoc.

io/blog/unix/3837/shell-script-to-make-a-menu-driven-calculator-using-
case

Logical Operators

a=10
b=20

if [ $a != $b ]
then
echo "$a != $b : a is not equal to b"
else
echo "$a != $b: a is equal to b"
fi

if [ $a -lt 100 -a $b -gt 15 ]


then
echo "$a -lt 100 -a $b -gt 15 : returns true"
else
echo "$a -lt 100 -a $b -gt 15 : returns false"
fi

if [ $a -lt 100 -o $b -gt 100 ]


then
echo "$a -lt 100 -o $b -gt 100 : returns true"
else
echo "$a -lt 100 -o $b -gt 100 : returns false"
fi

if [ $a -lt 5 -o $b -gt 100 ]


then
echo "$a -lt 100 -o $b -gt 100 : returns true"
else
echo "$a -lt 100 -o $b -gt 100 : returns false"
fi

OR operator

read -p "Enter First Numeric Value: " first


read -p "Enter Second Numeric Value: " second

if [ $first -le 10 -o $second -gt 20 ]


then
echo "OK"
else
echo "Not OK"
fi
echo "Enter a number: "

read a

# check

if [ `expr $a % 2` != 0 -o $a -lt 10 ]

then

echo "$a is either odd or less than 10."

else

echo "$a failed the test."

fi

and operator

echo "Enter a number: "

read a

# check

if [ `expr $a % 2` == 0 -a $a -gt 10 ]

then

echo "$a is even and greater than 10."

else

echo "$a failed the test."

fi

You might also like