![Bash-Befehle funktionieren nicht auf dem Mac](https://rvso.com/image/50592/Bash-Befehle%20funktionieren%20nicht%20auf%20dem%20Mac.png)
Hallo. Ich öffne mein Terminalfenster auf Mac OS 10.6.8, um mein Ruby auf 1.9.3 zu aktualisieren, und das Terminal gibt mir sofort beim Öffnen diese Antwort:
-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
Ich habe versucht, meinen Pfad zu ändern, aber es hat nicht funktioniert. Ich bin mir nicht sicher, wie ich dieses Problem angehen soll, und habe eine Menge Foren durchgelesen. Irgendwelche Ideen?
Hier ist das Bash-Profil:
$ /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.
Antwort1
OK, das Hauptproblem bestand hier darin, dass Sie Leerzeichen zwischen den Verzeichniseinträgen hatten $PATH
und dass Sie diese Leerzeichen in nicht in Anführungszeichen gesetzten Variablen hatten, was zu Verwirrung führte bash
.
In diesem Fall wollten Sie Ihrem Pfad ein Verzeichnis hinzufügen. Die korrekte Syntax lautet PATH="/foo:/bar/baz:$PATH
. Wenn Sie $PATH
am Ende das hinzufügen, wird der aktuelle Wert an das Ende der Variable angehängt. Auf diese Weise überschreiben Sie nicht, was bereits vorhanden war. Die Verzeichnisse in $PATH
werden der Reihe nach gelesen. Fügen Sie es also am Anfang hinzu, wenn die neuen Verzeichnisse zuletzt durchsucht werden sollen: PATH="$PATH:/foo:/bar"
.
Ein weiteres Problem war, dass Sie viele doppelte Pfade hatten. Sie können diese finden, indem Sie ausführen
$ 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
Schließlich haben Sie es mehrfach exportiert , was sinnlos ist. Ich habe alle Duplikate entfernt und Ihre Syntax korrigiert und bin zu folgendem Ergebnis gekommen:
# 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.
Kopieren Sie diese Datei, öffnen Sie Ihr Terminal und führen Sie diese Befehle aus:
/bin/cp ~/.bash_profile ~/bash_profile.bad
/bin/cat > ~/.bash_profile
Das erste erstellt eine Sicherungskopie Ihres aktuellen ~/.bash_profile
(nur für den Fall). Das zweite wird scheinbar nichts tun, aber es wird ~/.bash_profile
zum Schreiben geöffnet. Fügen Sie einfach das, was ich oben angegeben habe, direkt in das Terminal ein und drücken Sie Enterund dann CtrlC. Das sollte alles wieder normalisieren.
HINWEIS: Sie haben in Ihrem /bin
, und angegeben . Diese sind /sbin
mit ziemlicher Sicherheit bereits in Ihrem und müssen nicht hinzugefügt werden. Wenn sie fehlen ( um den aktuellen Wert anzuzeigen), fügen Sie sie einfach mit der oben beschriebenen Syntax hinzu./usr/bin
/usr/local/bin
.bash_profile
$PATH
echo $PATH