【问题标题】:missing end to balance this if statement缺少结束来平衡这个 if 语句
【发布时间】:2016-09-14 18:23:44
【问题描述】:

我尝试将此行添加到我的 .bash-profile

if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ];then
 source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh"
fi

但我收到此错误

Missing end to balance this if statement
.bash_profile (line 2): if [ -f "$(brew --prefix)/opt/bash-git-       prompt/share/gitprompt.sh" ]; then
                    ^
from sourcing file .bash_profile
called on standard input

有人知道为什么吗? 我有来自这里的代码 https://github.com/magicmonty/bash-git-prompt

【问题讨论】:

  • 为什么这个问题被标记为“鱼”?您是否尝试从鱼壳中获取您的.bash_profile? Fish 是具有不同语法的不同 shell;它与 bash 不兼容。
  • 感谢您的回答,我已删除标签
  • 不过,.bash_profile (line 2): 看起来像 fish 用于错误消息的格式。你确定你不是从fish 采购你的.bash_profile 吗?
  • 不要移除标签;这是完全相关的,因为您发布的错误消息来自fish,而不是bash
  • @Arthur 问题是,你运行的是fish,而不是bashgitprompt.sh 脚本与 fish 无关。在任何情况下,您都不应尝试在 fish 会话中获取 .bash_profile

标签: git bash shell unix fish


【解决方案1】:

虽然链接的存储库包含fish 的脚本,但自述文件并未提供有关如何使用该脚本的任何说明。好几年没用fish了,觉得你想做的就是添加

if status --is-login
  source (brew --prefix)"/opt/bash-git-prompt/share/gitprompt.fish"
end

改为~/.config/fish/config.fish。如果您没有启动交互式 shell,if status 命令可防止不必要地获取文件。

【讨论】:

  • 它正在工作,但还没有得到这个:/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python : 无法打开文件'/gitstatus.py': [Errno 2] 没有这样的文件或目录
  • 您还需要将 bash-git-prompt 安装中的 gitprompt.py 复制到 ~/.gitprompt,或者将 set __GIT_PROMPT_DIR (brew --prefix)"/opt/bash-git/prompt/share/" 之类的内容添加到您的 config.fish 文件中。
【解决方案2】:

这个错误信息:

Missing end to balance this if statement
.bash_profile (line 2): if [ -f "$(brew --prefix)/opt/bash-git-       prompt/share/gitprompt.sh" ]; then
                    ^
from sourcing file .bash_profile
called on standard input

fish shell 生成。

.bash_profile 文件仅供bash shell 执行(来源)。 fish 是一个不同的shell,具有不同的语法;它与bash 不兼容。

如果您使用fish 作为交互式shell,并且希望在启动新shell 时自动执行某些命令,则需要将特定于bash 的命令转换为fish 语法并添加将它们添加到您的 fish 启动文件中。 (使用fish 的人不多,因此软件包的提供者不太可能以fish 语法提供启动命令——但这个软件包显然提供了;请参阅chepner's answer。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-18
    • 1970-01-01
    • 2021-04-27
    • 2022-12-16
    • 2023-02-21
    • 1970-01-01
    • 1970-01-01
    • 2017-08-27
    相关资源
    最近更新 更多