bash 缺少结束来平衡这个 if 语句

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39497196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 15:10:26  来源:igfitidea点击:

missing end to balance this if statement

gitbashshellunixfish

提问by Arthur

i try to add this lines to my .bash-profile

我尝试将此行添加到我的 .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

but I get this error

但我收到这个错误

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

Dose anyone have an idea why? I have the code from here https://github.com/magicmonty/bash-git-prompt

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

采纳答案by chepner

Although the linked repository contains a script for fish, the README does not provide any directions for how to usethat script. Not having used fishin several years, I thinkwhat you want to do is add

尽管链接的存储库包含 的脚本fish,但自述文件没有提供有关如何使用该脚本的任何说明。由于没有使用fish好几年,我觉得你想要做的就是添加

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

to ~/.config/fish/config.fishinstead. The if statuscommand prevents the file from being unnecessarily sourced if you aren't starting an interactive shell.

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

回答by Keith Thompson

This error message:

此错误消息:

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

is generated by the fishshell.

fish外壳生成。

The .bash_profilefile is intended only to be executed (sourced) by the bashshell. fishis a different shell, with different syntax; it's not compatible with bash.

.bash_profile文件仅旨在由bashshell执行(来源)。fish是不同的外壳,具有不同的语法;它与bash.

If you're using fishas your interactive shell, and you want some commands to be executed automatically when you start a new shell, you'll need to translate the bash-specific commands to fishsyntax and add them to your fishstartup file. (Not a lot of people use fish, so providers of software packages aren't likely to provide startup commands in fishsyntax -- but this package apparently does; see chepner's answer.)

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