Dadzilla

Q: 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

Close

Q: I have accidentally destroyed my $PATH variable.

  • All replies
  • Helpful answers

  • by Tony T1,Helpful

    Tony T1 Tony T1 Jun 9, 2016 7:15 PM in response to Dadzilla
    Level 6 (9,232 points)
    Mac OS X
    Jun 9, 2016 7:15 PM in response to Dadzilla

    The path is in /etc

    Open Finder, then ⇧⌘G and enter: /etc

    There should be a file names paths

    The contents of the file is:

         /usr/local/bin

         /usr/bin

         /bin

         /usr/sbin

         /sbin

     

    If you want to add to the path, then place a file in the paths.d Folder (or in .bash_profile)

  • by BobHarris,

    BobHarris BobHarris Jun 9, 2016 5:55 AM in response to Dadzilla
    Level 6 (19,272 points)
    Mac OS X
    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.

  • by BobHarris,

    BobHarris BobHarris Jun 9, 2016 6:08 AM in response to Dadzilla
    Level 6 (19,272 points)
    Mac OS X
    Jun 9, 2016 6:08 AM in response to Dadzilla

    My mistake.  Corrrection.  Because your PATH is messed up specify

        /bin/ls -a

    and

        /bin/mv ...

    That way PATH will not be needed to list the contents of your home directory and move the files to a new name.

    Sorry I forgot to include the /bin prefix in my first examples.

  • by Mark Jalbert,

    Mark Jalbert Mark Jalbert Jun 9, 2016 8:16 AM in response to Dadzilla
    Level 5 (4,649 points)
    Jun 9, 2016 8:16 AM in response to Dadzilla

    You can get a usable PATH variable in your current terminal session by typing:

     

    PATH=$(/usr/bin/getconf PATH)

     

    then move (rename) your shell config files without having to use the absolute path to mv .

  • by Dadzilla,

    Dadzilla Dadzilla Jun 9, 2016 7:36 PM in response to Mark Jalbert
    Level 1 (4 points)
    Mac OS X
    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.

  • by Tony T1,

    Tony T1 Tony T1 Jun 10, 2016 5:34 AM in response to Dadzilla
    Level 6 (9,232 points)
    Mac OS X
    Jun 10, 2016 5:34 AM in response to Dadzilla

    The document you have for 10.6 should be sufficient for 10.9.5, but see if you can find anything here:

         https://developer.apple.com/library/mac/navigation/#section=Resource%20Types

     

    A quick search there for "shell" got me:

         https://developer.apple.com/library/mac/documentation/OpenSource/Conceptual/Shel lScripting/Introduction/Introduction.html

    which got me to:

         Command Line Primer

  • by BobHarris,

    BobHarris BobHarris Jun 10, 2016 6:26 AM in response to Dadzilla
    Level 6 (19,272 points)
    Mac OS X
    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.

  • by Mark Jalbert,

    Mark Jalbert Mark Jalbert Jun 10, 2016 10:04 AM in response to Dadzilla
    Level 5 (4,649 points)
    Jun 10, 2016 10:04 AM in response to Dadzilla

    Well, I'll recommend these crusty papers written by the folks that invented UNIX- http://plan9.bell-labs.com/7thEdMan/v7vol2a.pdf. Most of this information is still prevalent today. BTW- if you get through the ed tutorial, you will appreciate the WYSIWYG editors; vi, emacs, and nano...:-)