0

I believe I have a corrupted file in my bash unix shell on Mac OS X (10.12.3). Upon opening a terminal I don’t have access to bash. The only thing I can do is run % echo $PATH which returns:

/usr/local/share/npm/bin:/Users/greg/mongodb/bin:/Users/g

I can restore access to bash using

export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH

After doing this and checking the $PATH variable, I see

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/share/npm/bin:/Users/greg/mongodb/bin:/Users/g

However, if I open a new terminal window, none of the $PATH info that I just added is there.

Following this Stackoverflow post I'm looking at the places where these variables are supposed to be set.

Looking in /etc/paths I see the following:

/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
/Users/greg/mongodb/bin 

A /etc/profile doesn’t exist

My ~/.bash_profile looks like this

export PATH=/usr/local/share/npm/bin:/Users/greg/mongodb/bin:/Users/g
reg/anaconda2/bin:/Applications/Postgres.app/Contents/Versions/latest
/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/bin:/b
in:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/Library/Framewor
ks/Mono.framework/Versions/Current/Commands:/Applications/Visual
Studio Code.app/Contents/Resources/app/bin:

My ~/.profile looks like this

export NODE_PATH="/usr/local/lib/node"
export PATH="/usr/local/share/npm/bin:$PATH"
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

Everything looks okay to me. Does this indicate that bash is using another file to set the environment variables including $PATH info? If so, where is it located? And why don’t the $PATH variable changes I make persist?

Greg
  • 61
  • 1
  • 8
  • ~/.bash_profile looks thoroughly messed up; that looks like it should all be one long line, and (as zachdb86 said) should end with `:$PATH`. But there may be other, less obvious, problems as well. – Gordon Davisson Dec 12 '17 at 07:00

1 Answers1

0

When you export PATH in in any of your .profiles you must include $PATH, otherwise PATH will be overwritten. You do not do that in the last export of your .profile or in your .bash_profile.

Also, I would move NODE_PATH as well as your first export PATH... into .bash_profile and delete that final export path.

so your export statement would look like this:

export PATH=/usr/local/share/npm/bin:...:$PATH
zachdb86
  • 971
  • 1
  • 8
  • 13