echo " enter the number "
read a
fact = 1
while [ $a -gt 1 ]
do
fact = ` expr $fact \* $a `
a = ` expr $a - 1 `
done
echo " factorial of given number is $fact"
我想找到一个数字的阶乘。 显示的输出是
expr: syntax error
abc: 7: abc: fact: not found
abc: 8: abc: a: not found
答案 0 :(得分:2)
在=
之前或之后的作业cannot not have spaces,否则它们被解释为命令或不指定任何值:
echo " enter the number "
read a
fact=1
while [ $a -gt 1 ]
do
fact=`expr $fact \* $a`
a=`expr $a - 1 `
done
echo " factorial of given number is $fact"