Shell scripts
1)
echo enter two numbers
read a b
echo "Addition: $(($a + $b))"
echo "Subtraction: $(($a - $b))"
echo "AMultiplication: $(($a * $b))"
echo "Quotient: $(($a / $b))"
echo "Remainder: $(($a % $b))"
or
echo enter two numbers
read a b
s=`expr $a + $b`
echo sum=$s
s=`expr $a - $b`
echo Difference =$s
s=`expr $a \* $b`
echo Product =$s
s=`expr $a / $b`
echo quotient =$s
s=`expr $a % $b`
echo Remainder =$s
2) Greatest of three numbers
echo Enter three numbers
read a b c
if [ $a -gt $b -a $a -gt $c ]
then
echo $a
elif [ $b -gt $c -a $b -gt $a ]
then
echo $b
else
echo $c
fi
3) Menu driven program
echo -e "MENU\n 1. List of files\n 2. Processes of User\n 3. Today's Date \n4. Users of system\n 5. quit"
echo " Enter your option "
read choice
case "$choice" in
1) ls -l ;;
2) ps -f ;;
3) date ;;
4) who ;;
5) exit ;;
*) echo "Invalid option"
esac
4) Factorial
echo "Enter a number"
read n
f=1
while [ $n -ne 0 ]
do
f=$(($f * $n))
n=$(($n -1))
done
echo "Factorial ="$f