Name: echo "enter your name" read name echo $name Arithmetic Operators -- +,-,/,\* echo "enter the read num1 echo "enter the read num2 res=`expr $num1 echo "Addition
first number" second number" + $num2` = $res"
Relational Operators -eq -ne -gt -lt -ge -le Logical Operators -a -o ! Branching if .. then .. else .. fi if [condition] then statements elif statements fi
Example echo "enter employee's Basic" read sal
if [ $sal -gt 10000 ] then hra=`expr $sal / 5` elif [ $sal -ge 5000 -a $sal -le 10000 ] then hra=`expr $sal / 4` elif [ $sal -ge 1000 -a $sal -le 5000 ] then hra=`expr $sal / 4` else hra=`expr $sal / 3` fi echo "HRA $hra"
case .. esac Example for case .. esac echo "menu" echo "1.list of users logged in" echo "2.your current directory" echo "enter your choice" read choice case $choice in 1) pwd;; 2) who;; *) echo "Invalid choice";; Loops for .. do .. done Example - for .. do .. done
for a in 1 2 3 do echo "the number if $a" echo "square of the number if `expr $a \* $a`" done
while .. do .. done Example for while .. do .. done while true do echo "Do you wish to enter value ( y / Y )" read ch if [ $ch = Y -o $ch = y ] then echo "Hi $LOGNAME" fi done until .. do .. done Example
--
Until .. do .. done
until ls abc do echo "File not found" exit done echo "File abc found here"