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


  • 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)
export PATH

export MONGO_PATH=/usr/local/mongodb
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)

  • Apologies about the confusion. I will leave the question on how to find the bash_profile file without the terminal as closed/answered and move on, opening a the follow up /underlying question: what causes the infinite loop. – MyKMyk Apr 2 at 19:51
  • debug the startup file(s) is the core issue, indeed. Accepting your answer was my response since you helped solving a part of the issue. I didn't know that this was handled so narrow. This feels like conversations/comments on JIRA - One ticket, one issue. I will keep this in mind. – MyKMyk Apr 2 at 20:24
  • I read chameleon link: I am new, I don't have a degree in computer science. I took a few classes (C++, Java): super bad vibes. There was this constant underlying theme in class who is smart, who knows more which was killing the atmosphere, the flow, just toxic. I am a humanist, my first foreign language was ancient Latin (for 7 years) - meaning in the literal meaning of intelligent I learned how detect an intellect with certain sensitivities versus a curious mind seeking answers. In regard to some comments there, I am a bit shocked. I think, I have an idea now where you are coming from. Thx – MyKMyk Apr 2 at 20:40

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.

  • Try looking at the files you changed in text-edit then if you can't change them from the terminal – Kevin Rockwell Mar 27 at 21:13
  • Terminal was indeed my first idea - but again I can't. Maybe I delete java first (without terminal), reinstall and hope that the uninstall was clean enough to allow me to reinstall without the past setup. I can use the text editor but I don't know where I can find the java folder without the finder (newbee in the mac universe). How would I find /usr/libexec/java_home or `PATH/bin' without the terminal? – MyKMyk Mar 27 at 21:38
  • What files did you change in the Android download? And to go to the java folder you can use Shift-Command-G to go to files in finder, or the "go" menu and then the second to last entry. – Kevin Rockwell Mar 27 at 21:46
  • Open the profile in textedit by pressing Shift+Command+. (in Finder) in your home directory, then you should be able to open it in textedit – Kevin Rockwell Mar 27 at 21:58
  • @KamilMaciorowski done, ty! – MyKMyk Mar 27 at 22:02

I changed in the .bash_profile the

  • export PATH=$PATH:/bin


  • export PATH="/usr/local/bin:$PATH"

and the system is back to normal.


If I'm following correctly, you have the following line in your ~/.bash_profile:

source .bash_profile

The source command will load and process the cont content of the indicated file, which means that when the terminal starts it sources ~/.bash_profile, which then sources ~/.bash_profile, which then sources ~/.bash_profile, etc...

Removing that line will probably solve your issues.

  • Thanks for pointing this out. First I didn't realize the impact of this line. So I uninstalled java, reinstalled it and started with the bash_profile from the beginning. When I googled the issue/ youtubed it, ect. didn't find a lot of answers. I ended up leaving out source .bash_profile. Terminal stopped running the lines. Again, thanks for explaining this. Do you recommend a good source to look up the whole environment variables spiel? – MyKMyk Apr 10 at 0:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.