4

In the course of trying to install something on my Mac OSX machine, I think I have broken my ~/.bash_profile file. I edited it, and suddenly, now, when I open a terminal, I can't run anything, or even list files:

$ ls
-bash: ls: command not found

Oh no! I try to open emacs to edit ~/.bash_profile, but I can't:

$ 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.

I can't sudo, and I can't change Finder to show hidden files to open it from there either:

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

Help! How can I open ~/.bash_profile to fix it?

  • I think your notion of what constitutes "disaster recovery" might differ somewhat to most peoples'.... – skaffman Jul 31 '10 at 18:35
  • 4
    You can try something like: export PATH=/bin:/usr/bin:"$PATH" – asveikau Jul 31 '10 at 18:43
  • Sorry. I have realised that (a) this should be on superuser.com and (b) it's already been answered over there. Unfortunately it seems that I can't delete my question. I've flagged it asking for a moderator to delete it. – AP257 Jul 31 '10 at 18:45
  • As far as I know, you should be able to delete your own question. At the bottom left of the question, above the answers but below the tags, there should be some links like "edit | delete | flag". Anyway, I'm sure a moderator or the community will take care of closing/deleting this if it's warranted. – David Z Aug 1 '10 at 0:45
4

Use full paths to the commands until you fix your PATH:

/bin/ls
/path/to/emacs

etc.

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

... assuming your HOME isn't corrupted as well. Otherwise, cd to the right place and edit.

0

You probably corrupted your PATH environment variable...

Use finder to open the file in textwrangler or so.

0

Run this command to fix your bash profile, substituting your username in:

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

When editing your path don't forget to include :$PATH to the end of your new path string. Should read like this:

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

This is the likely cause of your problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy