I have accidentally destroyed my $PATH variable.

In bash, I have only a ">" at the command line and the system appears to be completely unresponsive to anything I type in the terminal. What is the default $PATH variable in OSX 10.9.5, what directory does it live in, and what is the best way to put the new default statement into the proper place? Thanks very much!

iMac, OS X Mavericks (10.9.2)

Posted on Jun 8, 2016 7:21 PM

Reply
8 replies

Jun 9, 2016 5:55 AM in response to Dadzilla

This generally happens, when one of the following files are modified, either by the user, or by some open source software being installed.


Chances are you have one of the following files and it has the bad PATH information

.profile

.bash_profile

.bash_login

.bashrc

Most of the above do not exist, but I strongly suspect one of them does.


The easiest thing to do is rename the offending file, then start a new Terminal session.

Terminal -> Shell -> New Command -> ls -a

This should display the contents of your home folder, including all the files that start with a period, such as the .profile, .bash_profile, .bash_login, or .bashrc


Once you know the name of the offending bash shell initialization script, you can rename it using:

Terminal -> Shell -> New Command -> mv .profile save.profile

Terminal -> Shell -> New Command -> mv .bash_profile save.bash_profile

Terminal -> Shell -> New Command -> mv .bash_login save.bash_login

Terminal -> Shell -> New Command -> mv .profile save.bashrc

Based on the previous ls -a command you should know which of the 'mv' commands you need to rename the offending shell initialization script.


Another approach is to download TextWrangler

<http://www.barebones.com/products/textwrangler/>

which is free, and can safely edit shell text files, plus it will actually display hidden files, such as the ones that start with a period.

Once you have safely moved or fixed the offending shell initialization script, you should be able to start a new Terminal session and have a clean PATH.

Now you can look at the old initialization script and fix it, knowing if you make any mistakes, you can use the above to get back to the beginning and try again.

Jun 9, 2016 7:36 PM in response to Mark Jalbert

Thanks to all. I apparently did not destroy my $PATH entirely - I just lost my way trying to get to it.


Tony's hint worked perfectly and I could see, to my relief, that my path was present and intact. However, my terminal was still useless, giving me "command not found" errors if it bothered to respond at all, which it generally didn't. All I had was a > prompt...


So I used BobHarris' first hint and renamed my .bash_profile, closed and reopened the terminal and Voila! - I had a working terminal.


So now, I'm ready to screw it all up again!


Do any/all of you recommend any good books from which to learn the Apple command line? I have old, distant Linux experience, but I'm now moving deeper into OS X and would like to avoid stumbling around in the dark as much as I currently am. I have an old Apple document for OS X 10.6, but would prefer the version appropriate to 10.9.5. Thanks again to all of you for your help.

Jun 10, 2016 6:26 AM in response to Dadzilla

Actually, that Linux experience, taken with a grain of salt, is more or less what you need to interact with the Terminal.


When using the Terminal you are working with the 'bash' shell, the same shell used on many Linux distributions, so any book on bash will be helpful.


Individual commands will be similar, but the command line options may be different, or a subset of what Linux has, so consume the command 'man' page if it does not behave as you expect.


I use the UNIX command line on Mac, Linux, Solaris, and AIX everyday, and 90% or more of the commands I use behave the same on all the platforms. It is only when I need to use some operating specific command, or start to use some less frequently used command option that I need to do something different for any given platform. And then some 'man' page consulting gets me through that.


If I need to do something a lot where there are differences, I just wrote my own script to test 'uname' and have the script do the correct thing for the operating system it is working on, so it becomes transparent to me.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

I have accidentally destroyed my $PATH variable.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.