Bash – Fixing PATH with Duplicate Entries

bashpathterminal

History: I had installed Selenium (java_home was already taking care of and working). Now I was installing Android Studio(mac) and needed to adjust the env for Java_home.
First I typed:

  • set Android_home
  • export Android_home=/Library/Android/Home
  • echo Android_home

then:

  • nano .bash_profile

Adding Android_home.

  • export Android_home=/Users/<username>/Library/Android/sdk
  • export PATH=$PATH:$Android_home/tools
  • export PATH=$PATH:$Android_home/tools/bin
  • export PATH=$PATH:$Android_home/platform-tools

Lastly: $ source .bash_profile

Then closed everything, reopened the terminal.
The terminal instantly was running this one particular line (infinite-wise).

-bash: export: 'PATH/bin': not a valid identifier

error in terminal

After a short while, it changes to

-bash: export: 'PATH/bin': not a valid identifier

-bash: /usr/libexec/java_home: Argument list too long

Thank you for taking the time to read my question.
[this is my first question ever. Apologies for newbee mistakes. ]

.bash_profile
[Opened text editor, pressed Command + Shift + > to show hidden files.]

Export JAVA_HOME=$(/usr/libexec/java_home)
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH

export MONGO_PATH=/usr/local/mongodb
export PATH=$PATH:$MONGO PATH/bin
export Android_home=/Users/<username>/Library/Android/sdk
export PATH=$PATH:$Android_home/tools
export PATH=$PATH:$Android_home/tools/bin
export PATH=$PATH:$Android_home/platform-tools
source .bash_profile

Update:
To isolate the problem further I commented everything out in bash_profile except one, Java:

  • export PATH=$JAVA_HOME/bin:$PATH
  • export JAVA_HOME=/usr/libexec/java_home
  • export JAVA_HOME=/usr/libexec/java_home -v 1.8

Now run echo $PATH
Result: /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/bin:/ over and over gain

another example:
I commented everything out in bash_profile except one:

  • export PATH=$PATH:/bin

save > close terminal > re-open > check the change with

  • echo $PATH

all the terminal shows is this repetition/loop

  • /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/bin:/bin:/bin:/bin:/bin:/bin:/bin:/bin:....endless bin

one more observation

In the very beginning, when I open the terminal, something is running in the background which prevents me from typing something into the terminal.
I need to press control + c to stop it. Couldn't find out what process this is.

Is it possible that the .bash_profile or etc/paths is in conflict with
.profile ?

In.profileis only one PATH:

(export PATH=~/.npm-global/bin:$PATH)

Best Answer

The most likely cause is you have problems with exports in your .bashrc or .bash_profile eg, export PATH=PATH/bin which should be export PATH=$PATH:/bin.
In order to change this outside of the Terminal, you can use Command+Shift+. to toggle hidden files in finder to allow you to edit with TextEdit or another editor.

Related Question