bash脚本中奇怪的“语法错误:文件意外结束" [英] Weired 'syntax error: unexpected end of file' in bash script

查看:74
本文介绍了bash脚本中奇怪的“语法错误:文件意外结束"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法确定以下脚本出了什么问题.

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" ] 
then 
  echo Pulling web on sharada from origin.
else 
  echo "Usage : arg x to push or y to pull."
fi

我在 xterm 的linux(Ubuntu)上.

I am on linux (Ubuntu) in xterm.

推荐答案

您最后缺少结尾的"fi". else if 构造实际上不是 elif 的延续,而是新的 if 存在于 else 子句中前一个 if .

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"

这篇关于bash脚本中奇怪的“语法错误:文件意外结束"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆