当我尝试运行脚本时,我得到"第9行:[2:命令未找到"错误.这是我的第一个bash脚本,所以我是一个完整的初学者.
#!/bin/bash
num1=0
num2=1
count=2
while [$count -le $1]
do
num3='expr $num1+$num2'
num1=$num2
num2=$num3
count='expr $count+1'
done
echo "Fib Num: $num3"
Run Code Online (Sandbox Code Playgroud)
在[
和周围添加空格]
.[
是一个命令,所以它必须是一个单独的单词.来自man bash
:
test expr
[ expr ]
Return a status of 0 or 1 depending on the evaluation of the
conditional expression expr. Each operator and operand must be
a separate argument. Expressions are composed of the primaries
described above under CONDITIONAL EXPRESSIONS.
Run Code Online (Sandbox Code Playgroud)