List

Syntax

if [ expression ]
then
   Statement(s) to be executed if expression is true
else
   Statement(s) to be executed if expression is not true
fi

Example

#!/bin/sh

a=10
b=20

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

Nested if-else

!/bin/bash
read -p “Enter value of i :” i
read -p “Enter value of j :” j
read -p “Enter value of k :” k
if [ $i -gt $j ]
then
if [ $i -gt $k ]
then
echo “i is greatest”
else
echo “k is greatest”
fi
else
if [ $j -gt $k ]
then
echo “j is greatest”
else
echo “k is greatest”
fi
fi

Leave a Reply

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

  Posts

1 2 3
September 24th, 2020

awk Pipes

Pipes AWK can receive input and send output to other commands via the pipe. $ echo -e “1 2 3 […]

September 24th, 2020

awk Passing variables

Passing variables to AWK AWK has theĀ -vĀ option which is used to assign values to variables. For the next program, we […]

September 24th, 2020

awk more

Passing variables to AWK Pipes-awk awk Spell Checking Rock Paper Scissor Marking Keywords

September 23rd, 2020

awk Begin and End

  AWK has several built-in variables. They are set by AWK when the program is run. We have already seen […]

September 23rd, 2020

awk Programming

The name awk comes from the initials of its designers: Alfred V. Aho, Peter J. Weinberger, and Brian W. Kernighan. […]

September 8th, 2020

Unix Variable $* and $# difference

Script #!/bin/bash echo “Using \”\$*\”:”for a in “$*”; doecho $a;done echo -e “\nUsing \$*:”for a in $*; doecho $a;done echo […]

September 8th, 2020

Unix Comparison Operator

Comparison Operators String Comparison Description Str1 = Str2 Returns true if the strings are equal Str1 != Str2 Returns true […]

September 6th, 2020

grep Command

The grep Command The grep command searches a file or files for lines that have a certain pattern. Syntax $grep […]

September 6th, 2020

Shell Case Statement

Syntax case word in pattern1) Statement(s) to be executed if pattern1 matches ;; pattern2) Statement(s) to be executed if pattern2 […]

September 6th, 2020

Shell if-elif-else Statement

Syntax if [ expression 1 ] then Statement(s) to be executed if expression 1 is true elif [ expression 2 […]