此脚本出现错误:
elif [ $operation = "man" ]; then
if [ $aug1 = "add" ]; then # <- Line 75
echo "Man Page for: add"
echo ""
echo "Syntax: add [number 1] [number 2]"
echo ""
echo "Description:"
echo "Add two different numbers together."
echo ""
echo "Info:"
echo "Added in v1.0"
echo ""
elif [ -z $aug1 ]; then
echo "Please specify a command to read the man page."
else
echo "There is no manual page for that command."
fi
我得到了这个错误:
calc_1.2: line 75: [: =: unary operator expected
发布于 2014-05-01 16:11:34
您还可以为变量设置一个默认值,这样就不需要使用两个"[",这相当于两个进程("[“实际上是一个程序),而不是一个进程)。
它遵循以下语法:${VARIABLE:-default}。
整个事情必须以这样一种方式来考虑,即这个“默认”值是与“有效”值/内容不同的东西。
如果由于某种原因这是不可能的,你可能需要添加一个步骤,比如检查是否有值,就像"if -z $VARIABLE;then echo“"the variable need to be fine”或"if!-z $VARIABLE;then #everything is fine,then# all is fine,继续执行脚本的其余部分“。
https://stackoverflow.com/questions/13617843
复制相似问题