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
missing end to balance this if statement
提问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 fish
in 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.fish
instead. The if status
command 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 fish
shell.
由fish
外壳生成。
The .bash_profile
file is intended only to be executed (sourced) by the bash
shell. fish
is a different shell, with different syntax; it's not compatible with bash
.
该.bash_profile
文件仅旨在由bash
shell执行(来源)。fish
是不同的外壳,具有不同的语法;它与bash
.
If you're using fish
as 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 fish
syntax and add them to your fish
startup file. (Not a lot of people use fish
, so providers of software packages aren't likely to provide startup commands in fish
syntax -- but this package apparently does; see chepner's answer.)
如果您fish
用作交互式 shell,并且希望在启动新 shell 时自动执行某些命令,则需要将特定于 bash 的命令转换为fish
语法并将它们添加到fish
启动文件中。(使用 的人并不多fish
,因此软件包的提供者不太可能在fish
语法中提供启动命令——但这个软件包显然提供了;请参阅chepner 的回答。)