Bash 命令在 Mac 上不起作用

Bash 命令在 Mac 上不起作用

您好,我在 Mac Os 10.6.8 上打开终端窗口,因为我正在尝试将 ruby​​ 更新到 1.9.3,终端在我打开它时立即给出以下响应:

-bash: export: /Library/Frameworks/Python.framework/Versions/Current/bin': not a valid identifier 
-bash: export:/Library/Frameworks/Python.framework/Versions/2.7/bin': not a valid identifier
-bash: export: /Library/Frameworks/Python.framework/Versions/Current/bin': not a valid identifier 
-bash: export:/Library/Frameworks/Python.framework/Versions/Current/bin': not a valid identifier 
-bash: export: /usr/bin': not a valid identifier 
-bash: export:/bin': not a valid identifier 
-bash: export: /usr/sbin': not a valid identifier 
-bash: export:/sbin': not a valid identifier 
-bash: export: /usr/local/bin': not a valid identifier 
-bash: export:/usr/local/git/bin': not a valid identifier 
-bash: export: /usr/X11/bin': not a valid identifier 
-bash: export:/Users/oskarniburski/.rvm/bin': not a valid identifier 
-bash: export: /usr/X11R6/bin': not a valid identifier 
-bash: export:/Library/Frameworks/Python.framework/Versions/Current/bin': not a valid identifier 
-bash: export: /Library/Frameworks/Python.framework/Versions/2.7/bin': not a valid identifier 
-bash: export:/Library/Frameworks/Python.framework/Versions/Current/bin': not a valid identifier 
-bash: export: /Library/Frameworks/Python.framework/Versions/Current/bin': not a valid identifier 
-bash: export:/usr/bin': not a valid identifier 
-bash: export: /bin': not a valid identifier 
-bash: export:/usr/sbin': not a valid identifier 
-bash: export: /sbin': not a valid identifier 
-bash: export:/usr/local/bin': not a valid identifier 
-bash: export: /usr/local/git/bin': not a valid identifier 
-bash: export:/usr/X11/bin': not a valid identifier 
-bash: export: /Users/oskarniburski/.rvm/bin': not a valid identifier 
-bash: export:/usr/X11R6/bin': not a valid identifier

我试图改变我的道路,但没有成功。我不知道如何解决这个问题,并且一直在阅读大量的论坛。有任何想法吗?

这是 bash_profile:

$ /bin/cat ~/.bash_profile

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

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

# 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 EPD_free-7.3-2
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
export PATH

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

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
export PATH=/usr/local/bin:/Library/Frameworks/Python.framework/Versions/3.3/bin /Library/Frameworks/Python.framework/Versions/Current/bin /Library/Frameworks/Python.framework/Versions/2.7/bin /Library/Frameworks/Python.framework/Versions/Current/bin /Library/Frameworks/Python.framework/Versions/Current/bin /usr/bin /bin /usr/sbin /sbin /usr/local/bin /usr/local/git/bin /usr/X11/bin /Users/oskarniburski/.rvm/bin /usr/X11R6/bin
export PATH=/usr/local/bin:/Library/Frameworks/Python.framework/Versions/3.3/bin /Library/Frameworks/Python.framework/Versions/Current/bin /Library/Frameworks/Python.framework/Versions/2.7/bin /Library/Frameworks/Python.framework/Versions/Current/bin /Library/Frameworks/Python.framework/Versions/Current/bin /usr/bin /bin /usr/sbin /sbin /usr/local/bin /usr/local/git/bin /usr/X11/bin /Users/oskarniburski/.rvm/bin /usr/X11R6/bin

##
# Your previous /Users/oskarniburski/.bash_profile file was backed up as /Users/oskarniburski/.bash_profile.macports-saved_2013-09-26_at_17:32:30
##

# MacPorts Installer addition on 2013-09-26_at_17:32:30: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.

答案1

好的,这里的主要问题是您的目录条目中有空格分隔$PATH,并且在非引用变量中也有这些空格,这会混淆bash.

在这种情况下,您想要做的是将目录添加到您的路径中。正确的语法是PATH="/foo:/bar/baz:$PATH.将 添加$PATH到末尾意味着它的当前值将附加到变量的末尾,这样您就不会覆盖已经存在的值。中的目录$PATH是按顺序读取的,因此如果您希望最后搜索新目录,请将其添加到开头:PATH="$PATH:/foo:/bar"

另一个问题是您有许多重复的路径。您可以通过运行找到这些

$ echo $PATH | perl -pne 's/:/\n/g' | sort | uniq -d
/bin
/Library/Frameworks/Python.framework/Versions/2.7/bin
/Library/Frameworks/Python.framework/Versions/3.3/bin
/Library/Frameworks/Python.framework/Versions/Current/bin
/sbin
/usr/bin
/usr/local/bin
/usr/sbin

最后,您多次导出,$PATH这是毫无意义的。我删除了所有重复项并修复了您的语法,最终得到以下结果:

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

# 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}"

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

# Load RVM into a shell session *as a function*
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" 
PATH="/usr/local/git/bin:/usr/X11/bin:/Users/oskarniburski/.rvm/bin:/usr/X11R6/bin:$PATH"

##
# Your previous /Users/oskarniburski/.bash_profile file was backed up 
# as /Users/oskarniburski/.bash_profile.macports-saved_2013-09-26_at_17:32:30
##

# MacPorts Installer addition on 2013-09-26_at_17:32:30: adding an appropriate PATH 
# variable for use with MacPorts.
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"

# Finished adapting your PATH environment variable for use with MacPorts.

复制该文件,打开终端并运行以下命令:

/bin/cp ~/.bash_profile ~/bash_profile.bad
/bin/cat > ~/.bash_profile

第一个将备份您当前的数据~/.bash_profile(以防万一)。第二个似乎什么也不做,但它会打开~/.bash_profile以供写入。只需将我上面给出的内容直接粘贴到终端中,然后点击Enter,然后点击CtrlC。这应该会让一切恢复正常。

注意:/bin您在/sbin.​这些几乎肯定已经在您的中,不需要添加。如果它们丢失(查看当前值),只需使用我上面描述的语法添加它们。/usr/bin/usr/local/bin.bash_profile$PATHecho $PATH

相关内容