Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Jul 31 '10 at 18:55

This question came from our site for professional and enthusiast programmers.

    
I think your notion of what constitutes "disaster recovery" might differ somewhat to most peoples'.... –  skaffman Jul 31 '10 at 18:35
2  
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

3 Answers 3

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

/bin/ls
/path/to/emacs

etc.

share|improve this answer
$ /usr/bin/vi ~/.bash_profile

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

share|improve this answer

You probably corrupted your PATH environment variable...

Use finder to open the file in textwrangler or so.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.