Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

JavaThug

macrumors newbie
Original poster
Aug 20, 2009
4
0
Cincinnati, OH
This shouldn't be difficult but...

I'm trying to set JAVA_HOME in my /<user>/.bash_profile with the following code:

export JAVA_HOME=/Library/Java/Home​

Going back to Terminal and running 'echo $JAVA_HOME' results in:

exporty/Java/Home​

Same problem with just about any export. GWT_HOME is also truncated. Any idea WTH is going on? This is driving me insane.
 
I'm trying to set JAVA_HOME in my /<user>/.bash_profile with the following code:

export JAVA_HOME=/Library/Java/Home​

Going back to Terminal and running 'echo $JAVA_HOME' results in:

exporty/Java/Home​

Same problem with just about any export. GWT_HOME is also truncated. Any idea WTH is going on? This is driving me insane.

You might have an embedded CR (carriage return) character in the shell variable JAVA_HOME or GWT_HOME. Or the .bash_profile file has some lines terminated with LF (line feed, newline) and some with CR, and the CRs are ending up embedded in shell-variable values rather than being interpreted as line-endings.

First, what text editor are you editing .bash_profile with? Does it have a way to convert line-endings to all newlines? Does it have a way to show all invisible chars? Try getting an editor like Text Wrangler (free) that does this.

Second, use the hexdump command in Terminal to display the .bash_profile's contents as hex, and look for any 0D characters (there should be none). If there are any, you need to figure out how to remove them or convert them to newlines (0A).

The reason I suspect embedded CRs is the displayed value is "exporty/Java/Home", and "export" has the same number of chars as "/Librar". So if the real value of JAVA_HOME is "export\r/Library/Java/Home", it would show up as you see on an echo.

Another thing to try is

echo "$JAVA_HOME" | hexdump

And look for an embedded CR (0d). Note that echo normally adds a newline (0a) so don't be surprised by that.
 
Fixed!

...display the .bash_profile's contents as hex, and look for any 0D characters (there should be none).

Thanks! That was it... two control chars (0d).

Normally I only edit that file with nano from the Terminal. This time I used TextWrangler and rewrote the file (just to be safe). All seems well now!
 
You know, that has caused me hours of debugging scripts.

Now I always turn on the hidden characters in Komodo Edit, and I double check ftp settings, etc.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.