bash .bash_profile 语法错误:文件意外结束

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41815171/
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:39:10  来源:igfitidea点击:

.bash_profile syntax error: unexpected end of file

bashmacosunixmacos-sierra.bash-profile

提问by Brad.R

OS: macOS Sierra v10.12.2

操作系统:macOS Sierra v10.12.2

I was trying to get R working from the command line and ran into this problem, probably because I am relatively new to coding and messed with something I should not have.

我试图让 R 从命令行工作并遇到了这个问题,可能是因为我对编码比较陌生,并且弄乱了我不应该拥有的东西。

Upon opening new terminal:

打开新终端后:

-bash: /Users/Brad/.bash_profile: line 33: syntax error: unexpected end of file

When I inspect the profile it looks like this:

当我检查配置文件时,它看起来像这样:

# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

# Setting PATH for Python 3.5
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH

export PATH="$HOME/.bin:$PATH"

eval "$(hub alias -s)"

  prompt_ruby_info() {
    if [ -f ".ruby-version" ]; then
      cat .ruby-version
    fi
  }

GREEN=$(tput setaf 65)

ORANGE=$(tput setaf 166)

NORMAL=$(tput sgr0)

precmd () { PS1="${ORANGE}[%~] ${GREEN}$(prompt_ruby_info) ${NORMAL}$ " }

export CLICOLOR=1;

export LSCOLORS=Gxfxcxdxbxegedabagacad;

Any information on how to resolve this issue would be much appreciated; I don't want to keep messing around and making it worse!

任何有关如何解决此问题的信息将不胜感激;我不想继续胡闹,让事情变得更糟!

Thank You!

谢谢你!

回答by Fred

This line :

这一行:

precmd () { PS1="${ORANGE}[%~] ${GREEN}$(prompt_ruby_info) ${NORMAL}$ " }

Misses a semi-colon at the end :

最后漏掉一个分号:

precmd () { PS1="${ORANGE}[%~] ${GREEN}$(prompt_ruby_info) ${NORMAL}$ " ; }

From the Bash reference manual :

来自 Bash 参考手册:

{ list; }

Placing a list of commands between curly braces causes the list to be executed in the current shell context. No subshell is created. The semicolon (or newline) following list is required.

{ 列表; }

将命令列表放在大括号之间会导致列表在当前 shell 上下文中执行。没有创建子shell。以下列表中的分号(或换行符)是必需的。

This means you could also write :

这意味着你也可以写:

precmd ()
{
  PS1="${ORANGE}[%~] ${GREEN}$(prompt_ruby_info) ${NORMAL}$ "
}

回答by Ishtiyaq Husain

You are missed semicolon (;) at line number 27:

您错过了第 27 行的分号 (;):

precmd () { PS1="${ORANGE}[%~] ${GREEN}$(prompt_ruby_info) ${NORMAL}$ "; }