I am learning bash scripting and currently having trouble with an if statement inside a function. The following code returns two errors; both of which reference the if and elif conditions and say [: 12000: unary operator expected.
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)
I have tried using double square brackets, but I'm given a syntax error for some reason. Could someone explain the reason for the error above and for the syntax error when I use [[ some_condition ]] instead of [ some_condition ].
>=but-ge. Look intoman test(testshould be the same as[)