我打破了我的.bash_profile


4

在尝试在我的Mac OSX机器上安装某些东西的过程中,我想我已经破坏了我的〜/ .bash_profile文件。我编辑了它,突然,现在,当我打开终端时,我无法运行任何内容,甚至列出文件:

$ ls
-bash: ls: command not found

不好了!我尝试打开emacs来编辑〜/ .bash_profile,但我不能:

$ emacs ~/.bash_profile
-bash: emacs: command not found
$ port install emacs
MacPorts running without privileges. You may be unable to complete certain actions (eg install).
--->  Computing dependencies for emacs
MacPorts running without privileges. You may be unable to complete certain actions (eg install).
--->  Fetching emacs
--->  Attempting to fetch emacs-23.2.tar.gz from http://www.mirrorservice.org/sites/ftp.gnu.org/gnu/emacs
MacPorts running without privileges. You may be unable to complete certain actions (eg install).
--->  Verifying checksum(s) for emacs
MacPorts running without privileges. You may be unable to complete certain actions (eg install).
--->  Extracting emacs
MacPorts running without privileges. You may be unable to complete certain actions (eg install).
MacPorts running without privileges. You may be unable to complete certain actions (eg install).
--->  Configuring emacs
MacPorts running without privileges. You may be unable to complete certain actions (eg install).
--->  Building emacs
MacPorts running without privileges. You may be unable to complete certain actions (eg install).
--->  Staging emacs into destroot
MacPorts running without privileges. You may be unable to complete certain actions (eg install).
--->  Installing emacs @23.2_1
Error: Target org.macports.install returned: MacPorts requires root privileges for this action
Error: Status 1 encountered during processing.
Before reporting a bug, first run the command again with the -d flag to get complete output.

我不能sudo,我不能改变Finder显示隐藏文件从那里打开它:

$ sudo port install emacs
-bash: sudo: command not found
$ defaults write com.apple.Finder AppleShowAllFiles YES
-bash: defaults: command not found

救命!如何打开〜/ .bash_profile来修复它?


我认为你对什么构成“灾难恢复”的看法可能与大多数人的情况有所不同......
skaffman 2010年

4
您可以尝试以下方式:export PATH=/bin:/usr/bin:"$PATH"

抱歉。我已经意识到(a)这应该在superuser.com上,并且(b)它已经在那里得到了解答。不幸的是,我似乎无法删除我的问题。我已将其标记为要求主持人删除它。

据我所知,您应该可以删除自己的问题。在问题的左下角,在答案之上但在标签下方,应该有一些像“edit | delete | flag”这样的链接。无论如何,我确信如果有必要,主持人或社区将负责关闭/删除此项。
大卫Z 2010年

Answers:



3
$ /usr/bin/vi ~/.bash_profile

...假设你的HOME身体也没有被破坏。否则,cd到正确的地方并编辑。


0

您可能损坏了PATH环境变量...

使用finder在textwrangler中打开文件。


0

运行此命令以修复您的bash配置文件,用您的用户名替换:

/usr/bin/sudo /usr/bin/nano /Users/YOURUSERNAME/.bash_profile

编辑路径时,不要忘记:$ PATH到新路径字符串的末尾。应该是这样读的:

export PATH = "/my/new/path:$PATH"

这可能是您遇到问题的原因。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.