Reputation: 9
Why isn't this if-else operation working? I fixed my spacing many times yet getting the error syntax error near unexpected token `elif' , I have tried using "==" instead of "=", I have tried using two third brackets but nothing seems to work.
if [ "$operation" = "+" ]
then addition()
elif [ "$operation" = "-" ]
then subtraction()
elif [ "$operation" = "*" ]
then multiplication()
elif [ "$operation" = "/" ]
then division()
fi
Upvotes: 0
Views: 230
Reputation: 1303
You should remove parantheses to call the function. Whenever you encounter syntax issues like this, please use shellcheck website to identify what's wrong.
if [ "$operation" = "+" ]
then addition
elif [ "$operation" = "-" ]
then subtraction
elif [ "$operation" = "*" ]
then multiplication
elif [ "$operation" = "/" ]
then division
fi
Upvotes: 3