I've broken my .bash_profile

4

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?

AP257

Posted 2010-07-31T18:33:39.003

Reputation:

I think your notion of what constitutes "disaster recovery" might differ somewhat to most peoples'.... – skaffman – 2010-07-31T18:35:12.510

4You can try something like: export PATH=/bin:/usr/bin:"$PATH" – None – 2010-07-31T18:43:21.197

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. – None – 2010-07-31T18:45:14.217

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 – 2010-08-01T00:45:44.737

Answers

4

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

/bin/ls
/path/to/emacs

etc.

Paused until further notice.

Posted 2010-07-31T18:33:39.003

Reputation: 86 075

3

$ /usr/bin/vi ~/.bash_profile

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

Fred

Posted 2010-07-31T18:33:39.003

Reputation: 1 205

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.

Gremlin

Posted 2010-07-31T18:33:39.003

Reputation: 1

0

You probably corrupted your PATH environment variable...

Use finder to open the file in textwrangler or so.

hvgotcodes

Posted 2010-07-31T18:33:39.003

Reputation: 748