私は、挿入された数の階乗を与えるスクリプトを作成していますが、私は乗算にいくつか問題があります。変数の乗算
注:!のための階乗は次式で与えられます。9 = 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1
は、ここに私のコードです:
#!/bin/bash
echo "Insert an Integer"
read input
if ! [[ "$input" =~ ^[0-9]+$ ]] ; then
exec >&2; echo "Error: You didn't enter an integer"; exit 1
fi
function factorial
{
while [ "$input" != 1 ];
do
result=$(($result * $input))
input=$(($input-1))
done
}
factorial
echo "The Factorial of " $input "is" $result
それは続けてdiferent乗算テクニクスのために私のすべての種類のエラーを与える:/
すると、現在の出力は次のとおりです。
[email protected] ~/Área de Trabalho/Shell $ ./factorial.sh
Insert an Integer
3
./factorial.sh: line 15: * 3: syntax error: operand expected (error token is "* 3")
The factorial of 3 is
多くのおかげで、 よろしく
どのようなエラーが生じますか? – iamnotmaynard