Write a shell script to calculate factorial of a given integ
Write a shell script to calculate factorial of a given integer number. Please name your shell script as factorial. sh. The integer number should be given on command line. The sample outputs are as below: $./factorial.sh 2 the factorial of 2 is 2 $./factorial of 4 the factorial of 4 is 24 $, /factorial.sh 5 the factorial of 4 is 120
Solution
#!/bin/bash
num=$1
ans=1
count=0
while [ $num -ne $count ]
do
count=`expr $count + 1`
ans=`expr $ans \\* $count`
done
echo \"The factorial of $num is $ans\"
