Discussion in 'Mac Programming' started by JavaThug, Aug 20, 2009.

  1. JavaThug macrumors newbie

    Aug 20, 2009
    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:


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

    Aug 9, 2009
    Sailing beyond the sunset
    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.
  3. JavaThug thread starter macrumors newbie

    Aug 20, 2009
    Cincinnati, OH

    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!
  4. iShater macrumors 604


    Aug 13, 2002
    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.

Share This Page