IF condition syntax with examples in Linux / Unix

IF condition syntax with examples in Linux / Unix

There are many conditions and loops are used in Linux / Unix shell scripting. In this post i am going to explain about IF condition syntax and with an example in Linux / Unix.

Syntax:

‘if’ Statement
The ‘if’ statement evaluates a condition which accompanies its command line.

syntax:

if condition_is_true
then
execute commands
else
execute commands
fi

Example:

#cat > if.sh

a=10
b=15
if [ a > b ]
then
echo “$a is greater than $b”
else
echo “$b is greater than $a”
fi

OK!. Lets execute the script and see the output. Previously  we have seen how to execute a shell, Perl and python script in linux.

#sh if.sh
10 is greater than 15

IF condition syntax with examples in Linux / Unix

 




One thought on “IF condition syntax with examples in Linux / Unix

Leave a Reply

Your email address will not be published. Required fields are marked *