if test-commands; then
consequent-commands;
[elif more-test-commands; then
more-consequents;]
[else alternate-consequents;]
fi
执行 test-commands 列表,如果其返回状态为零,则执行 consequent-commands 列表。
''=1
在 bash 中显示状态。
''=1
bash: =1: command not found
echo $?
127
status 的值为 127,而不是零。奇怪的说法:
if [ ''=1 ] ; then echo "true"; else echo "false"; fi
true
为什么状态值127
,而不是零调用 then 语句?为什么进不去false
bash?
@德米特里沙托夫
=1
bash: =1: command not found
echo $?
127
''=1
被解释为一个字符串=1
并且test找到一个非空字符串。如果你想比较''
到1
,写
[ '' = 1 ]
man bash
... 如果该函数未定义,shell 会打印一条错误消息并返回退出状态 127。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句