Bash scripting Find Factorial Of Given Number in Linux shell program

Linux and UNIX shell program or bash script it will find the factorial of the given number. Unix shell program expression option –eq refers to the equal and –le refer to the less than or equal to using expr keyword we perform the mathematical calculation. Shell program it will display output using echo command CS1252 Operating Systems lap
Source code bash shell Programming Algorithm
echo " Enter the number for which factorial is to be found "
read n
f=1
a=0
i=1
if [ $n -eq $a ]
then
echo $f
else
while [ $i -le $n ]
do
f=`expr $f \* $i`
i=`expr $i + 1`
done
fi
echo " The factorial of the number is "
echo $f

OUTPUT FACTORIAL OF A GIVEN NUMBER CS1252 Operating Systems lap
[redhat35@localhost Rhel5]$sh fact.sh
Enter the number for which factorial is to be found
5
The factorial of the number is
120

Related post