为什么这个if-else操作不起作用?我多次修正了我的间距,但在意外的标记"elif"附近出现了语法错误,我尝试使用"=="而不是"=&";,我试过用两个第三方括号,但似乎都不起作用。
if [ "$operation" = "+" ]
then addition()
elif [ "$operation" = "-" ]
then subtraction()
elif [ "$operation" = "*" ]
then multiplication()
elif [ "$operation" = "/" ]
then division()
fi
您应该删除Paranthes来调用函数。每当你遇到这样的语法问题时,请使用shellcheck网站来确定问题所在。
if [ "$operation" = "+" ]
then addition
elif [ "$operation" = "-" ]
then subtraction
elif [ "$operation" = "*" ]
then multiplication
elif [ "$operation" = "/" ]
then division
fi