我正在学习基于 Bourne shell 的 Korn shell。下面是我非常简单的代码。
read ab
if [ $ab = "a" || $ab = "A" ] ; then
echo hi
fi
由于某种原因,||
操作员给了我错误:
[: missing `]'
a: command not found
写出if
条件的正确方法是:
read ab
if [ "$ab" = "a" ] || [ "$ab" = "A" ]; then
echo hi
fi
使用[ ... ]
,必须将变量放在双引号中。否则,如果变量扩展为空或者它们的扩展包含空格,shell 将失败并出现语法错误。
也可以看看:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句