1) Write a shell script to scans the name of the command and executes it.
Program :-
echo "enter command name"
read cmd
$cmd
Output :-
enter command name
cal
February 2016
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29
2) Write a shell script Which works like calculator and performs below operations Addition
, Subtract ,Division ,Multiplication
Program :-
i) using if..elif statement
echo " Enter one no."
read n1
echo "Enter second no."
read n2
echo "1.Addition"
echo "2.Subtraction"
echo "3.Multiplication"
echo "4.Division"
echo "Enter your choice"
read ch
if [ $ch = "1" ]
then
sum=`expr $n1 + $n2`
echo "Sum ="$sum
elif [ $ch = "2" ]
then
sum=`expr $n1 - $n2`
echo "Sub = "$sum
elif [ $ch = "3" ]
then
1
, Unix Shell Scripts
sum=`expr $n1 \* $n2`
echo "Mul = "$sum
elif [ $ch = "4" ]
then
sum=`expr $n1 / $n2`
echo "Div = "$sum
fi
Output :-
Enter one no.
32
Enter second no.
12
1.Addition
2.Subtraction
3.Multiplication
4.Division
Enter your choice
2
Sub = 20
ii) using while loop and switch statement
i="y"
while [ $i = "y" ]
do
echo " Enter one no."
read n1
echo "Enter second no."
read n2
echo "1.Addition"
echo "2.Subtraction"
echo "3.Multiplication"
echo "4.Division"
echo "Enter your choice"
read ch
case $ch in
1) sum=`expr $n1 + $n2`
echo "Sum ="$sum;;
2)sum=`expr $n1 - $n2`
echo "Sub = "$sum;;
3)sum=`expr $n1 \* $n2`
2