AND and OR Operators in Bash scripting

Hey guys, here we will discuss how to use AND and OR Operator in Bash Scripting, 

AND operator

we can mention AND operator "-a"  "&"
simple example for AND Operator.

#!/bin/bash
echo "Enter SSC marks: " 
read SSC
echo "Enter Inter Marks: "  
read Inter

if [ $SSC -ge 70  -a  $Inter -gt 60 ]
#if [ $SSC -ge 70 ] & [ $Inter -ge 60 ]

then
        echo "Candidate Eligible"
else
echo "Candidate Not Eligible"

fi

OR Operator

we can mention AND operator "-o"  "||"
simple example for OR Operator.

#!/bin/bash
echo "Enter SSC Percentage: " 
read SSC
echo "Enter Inter Percentage: "  
read Inter

#if [ $SSC -ge 70  -o  $Inter -gt 60 ]
if [ $SSC -ge 70 ] || [ $Inter -ge 60 ]
then
        echo "Candidate Eligible"
else
echo "Candidate Not Eligible"
fi

Next Post Previous Post
No Comment
Add Comment
comment url