我正在学习bash脚本,并且当前在函数内部有一个if
语句。以下代码返回两个错误;两者都参考if
和elif
条件并且说[: 12000: unary operator expected
。Bash函数:一元运算符预期错误
function calculateBonus {
# If the sales figure is greater than 1 million, bonus is £1500
if [ $1 >= 1000000 ]
then
bonus=1500
# If greater than 100000, bonus is £750
elif [ $1 >= 100000 ]
then
bonus=750
else
bonus=0
fi
# Return the bonus figure
return $bonus
}
read sales
bonus=$(calculateBonus $sales)
我已经尝试使用双方括号,但由于某种原因,我给了一个语法错误。有人可以解释上述错误的原因以及当我使用[[ some_condition ]]
而不是[ some_condition ]
时的语法错误。
IIRC更大平等的操作符不是'> ='而是'-ge'。看看'man test'('test'应该和'''相同' –