Search code examples
javashellcommand-promptgit-bashjava-home

echo %JAVA_HOME% works in cmd, but not in git bash


Windows 10 user. I recently installed git for the first time, but ran into a peculiar issue. I was told that I needed to set the JAVA_HOME environment variable if I wanted to use java within git.

I was able to get JAVA_HOME properly changed for command prompt, but I couldn't get the same change to show up in git bash. Typing in echo %JAVA_HOME% would return a proper path in command prompt, but it would return %JAVA_HOME% in git bash.

I went into system settings and changed the system variable so that JAVA_HOME was pointing to my jdk. I updated the PATH variable in both system and environment variables to point to the bin and the jdk. I closed and reopened both git bash and command prompt. I restarted my machine, and even reinstalled both git and my jdk. I took my jdk from Java 10.0.2 down to the latest java 8 (171).

None of it has worked. I've gone through countless SO posts. What am I doing wrong?


Solution

  • Turns out, (git) BASH TERMINAL uses a completely different syntax to do echo than COMMMANDLINE TERMINAL.

    I had been doing echo %JAVA_HOME% when I should have been doing echo $JAVA_HOME.

    I couldn't see that I was supposed to be using $ and not % sign because the symbols looked so similar in my font. I only found out after copy/pasting an answer out of frustration into bash and having it magically work when it hadn't worked prior.

    But yes, the answer is to use $ and not % because they mean completely different things. Git bash uses $, command prompt uses %. You'd think they'd just use the same symbol to get the job done.