“unary operator expected” error in Bash if condition

前端 未结 4 1958
无人及你
无人及你 2020-11-27 09:23

I\'ve been trying to figure out whats wrong with this but just can\'t figure it out..

This is the part seems to be getting an error..

elif [ $operati         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 10:10

    Took me a while to find this but note that if you have a spacing error you will also get the same error:

    [: =: unary operator expected
    

    Correct:

    if [ "$APP_ENV" = "staging" ]
    

    vs

    if ["$APP_ENV" = "staging" ]
    

    As always setting -x debug variable helps to find these:

    set -x
    

提交回复
热议问题