Weired 'syntax error: unexpected end of file' in bash script

前端 未结 4 734
孤城傲影
孤城傲影 2021-01-27 23:37

I can\'t figure out what is wrong with following script.

#!/bin/bash 
if [ \"$1\" = \"x\" ] 
then
  echo Pushing web on sharada to origin.
else if [ \"$1\" = \"y         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-27 23:51

    you are missing closing "fi" at the end. the else if construct really is not an elif continuation, but instead the new if lives within the else clause of the previous if.

    so, properly formatted you should have:

    #!/bin/bash 
    if [ "$1" = "x" ] 
    then
      echo Pushing web on sharada to origin.
    else 
      if [ "$1" = "y" ] 
      then 
        echo Pulling web on sharada from origin.
      else 
        echo "Usage : arg x to push or y to pull."
      fi
    fi # <-- this closes the first "if"
    

提交回复
热议问题