0% found this document useful (0 votes)
27 views1 page

Shell Scripting Ex

This shell script prompts the user to enter a number, then uses a while loop to calculate the factorial of that number. It initializes a result variable to 1, then multiples it by each integer from 2 to the entered number. After the loop, it displays the factorial result.

Uploaded by

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

Shell Scripting Ex

This shell script prompts the user to enter a number, then uses a while loop to calculate the factorial of that number. It initializes a result variable to 1, then multiples it by each integer from 2 to the entered number. After the loop, it displays the factorial result.

Uploaded by

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

SHELL SCRIPTING

echo "Enter a number: "

read num

i=2

res=1

if [ $num -ge 2 ]

then

while [ $i -le $num ]

do

res=`expr $res \* $i`

i=`expr $i + 1`

done

echo "Factorial of $num = $res"

You might also like