Bash命令在Mac上不起作用

拉克索·兹罗宾(Rakso Zrobin)

您好,我在Mac Os 10.6.8上打开终端窗口,因为我正尝试将红宝石更新为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.
芒登

好的,这里的主要问题是您的目录中有空格分隔目录条目,$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这些几乎可以肯定已经存在$PATH,不需要添加。如果缺少它们(echo $PATH查看当前值),请使用我上面描述的语法添加它们。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章