【问题标题】:Syntax error in .bashrc after installing gsutil安装 gsutil 后 .bashrc 中的语法错误
【发布时间】:2017-02-13 13:19:38
【问题描述】:

在 Linux 机器上,我正在尝试按照https://cloud.google.com/storage/docs/gsutil_install 上的说明安装 gsutil。在安装过程中,我对所有内容都回答“是”并将其保留为默认值。

但是,现在,如果我打开一个新终端,它会以 bash 错误开始:

bash: /home/kurt/.bashrc: line 119: syntax error near unexpected token `fi'
bash: /home/kurt/.bashrc: line 119: `fi'
kurt@kurt-ThinkPad:~$

违规行包含在我的.bashrc 文件的以下 sn-p 中:

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi
  source '/home/kurt/Downloads/google-cloud-sdk/path.bash.inc'
fi
  source '/home/kurt/Downloads/google-cloud-sdk/completion.bash.inc'
fi

错误发生在倒数第二个fi 语句中。实际上,看起来最后两个 fis 与任何 if 都不匹配。我可以注释掉最后三行,但我不确定这是否会破坏功能。有什么建议吗?

【问题讨论】:

  • 为什么最后3行毫无逻辑地挂了?
  • 这也让我感到困惑。 Google 似乎不太可能发布带有语法错误的代码,但这些行似乎是由安装程序添加的。

标签: bash gsutil


【解决方案1】:

通过查看您的 .bashrc sn-p,您不会通过删除最后两个 fi 关键字来破坏任何功能。可能文件前面有一个对应的if关键字,但是按照前一个块的缩进和内容(配置bash完成),我怀疑。

我猜缺少的行是在尝试source它们之前检查这两个文件是否存在(并且可读):

if [ -r '/home/kurt/Downloads/google-cloud-sdk/path.bash.inc' ]; then
  source '/home/kurt/Downloads/google-cloud-sdk/path.bash.inc'
fi

if [ -r '/home/kurt/Downloads/google-cloud-sdk/completion.bash.inc' ]; then
  source '/home/kurt/Downloads/google-cloud-sdk/completion.bash.inc'
fi

生成这些行的安装程序中似乎存在错误。为了安全起见,我会重新下载软件包并再次运行安装程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-15
    • 1970-01-01
    • 2020-12-26
    • 2014-10-25
    • 1970-01-01
    • 2019-01-07
    • 1970-01-01
    相关资源
    最近更新 更多