1

I've been setting new softwares(mongoDB, maven etc) on my MAC. I think I overwrote the original .bash_profile while I worte the new PATH. And now most of the basic command in bash shell is not working.

-bash: ls: command not found

Following is the my .bash_profile opened in text editor.

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

export PATH=/Users/sychung/mongoDB/bin

#maven PATH
export M2_HOME=/Users/sychung/apache-maven-3.1.1
export PATH=$PATH:$M2_HOME/bin

# Setting PATH for Python 3.4
# The orginal version is saved in .bash_profile.pysave

PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"

# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

And the following is the list of PATH when I typed in "echo $PATH" in the shell.

/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/Users/sychung/mongoDB/bin:/Users/sychung/apache-maven-3.1.1/bin

What should I do to make the bash go back to normal?

Based on other comments, I've typed in the following in the shell and it looked like work again. However, when I restart the terminal, it goes back to "command not found" mode again and again.

PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
export PATH
summost
  • 13
  • 3

2 Answers2

1

You seem to think that export will take the current value of PATH in your file and append it to the value currently in the environment. However, the export command does only one thing: it marks the name PATH with the export attribute. When it comes time to set up the environment for a subprocess, the shell takes the current value of all names with the export attribute and adds them to that environment.

Note that once a process starts, there is no difference between variables with the export attribute set (whether inherited from the parent or set locally) and variables without; they are all simply shell variables.

When you set PATH to a single directory, that overwrites the current value of PATH and loses all the previous directories you included.

A correct way to add directories to your path is

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

PATH=$PATH:/new/dircetory
PATH=$PATH:/another/new/one
PATH=/a/very/important/one:$PATH    # you can prepend as well
chepner
  • 497,756
  • 71
  • 530
  • 681
0

Ultimately the problem is export PATH=/Users/sychung/mongoDB/bin which, unlike all the other lines that sets PATH, doesn't also include the current $PATH value and so removes the default PATH entries. Make that line look like the other lines (include $PATH somewhere in it) and things should work.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148