0% found this document useful (0 votes)
3 views

Shell scripts

The document contains several shell script examples for basic arithmetic operations, finding the greatest of three numbers, a menu-driven program for system tasks, and calculating the factorial of a number. Each script prompts the user for input and performs the specified operations, displaying the results accordingly. These examples illustrate fundamental scripting techniques in a Unix-like environment.

Uploaded by

wgfbwivbzlmktlz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Shell scripts

The document contains several shell script examples for basic arithmetic operations, finding the greatest of three numbers, a menu-driven program for system tasks, and calculating the factorial of a number. Each script prompts the user for input and performs the specified operations, displaying the results accordingly. These examples illustrate fundamental scripting techniques in a Unix-like environment.

Uploaded by

wgfbwivbzlmktlz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like