#!/bin/bash
f=1
c=$1
while [[ $c != 0 ]]
do
$f=$(($c*$f))
$c=$(($c-1))
done
echo $c
我一直收到错误
./process.sh: line 8: 1=0: command not found
./process.sh: line 7: 5=5: command not found
运行./process.sh 5
答案 0 :(得分:5)
$
表示“值”,因此$f
会对字符串文字1
进行评估。所以......
$f=$(($c*$f))
$c=$(($c-1))
应该是
f=$(($c*$f))
c=$(($c-1))
答案 1 :(得分:1)
在循环中,它应该是
f=$(($c*$f))
c=$(($c-1))