0
#!/bin/bash
a=0
while ["$a" -lt 10]
do
a=`expr "$a" + 1`
echo $a
done
这是错误:shell脚本,而环路误差
a.sh: 3: a.sh: [0: not found
#!/bin/bash
a=0
while ["$a" -lt 10]
do
a=`expr "$a" + 1`
echo $a
done
这是错误:shell脚本,而环路误差
a.sh: 3: a.sh: [0: not found
你需要保持空间周围的括号:
while [ "$a" -lt 10 ]
因为庆典interpretes串;它使用空格来分隔单词。当你写["$a"
;然后bash读取:[0
(在$ a替换为0之后)
对不起,删除重复答案! – aliasav
谢谢,太棒了! –
http://www.shellcheck.net/对于此类错别字非常方便 – Sundeep
可能的重复[如何比较两个字符串变量'if'语句在Bash?](http://stackoverflow.com/questions/4277665/how-do-i-compare-two-string-variables-in-an-if-statement-in-bash),或[为什么应该在那里在'\ ['之前和'\]'在Bash脚本之前是空格吗?](http://stackoverflow.com/questions/9581064/why-should-there-be-a-space-after-and-before -in-a-bash-script) –