Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 02-21-2011, 11:57 AM   #1
LQ Newbie
Registered: Feb 2011
Posts: 2

Rep: Reputation: 0
Variable expansion in .bashrc not working as I expect it to

In my .bashrc file, I am attempting to set JAVA_PATH to a local path, using the HOME environment variable or '~' symbol as shown in the following examples.

Using ${HOME}

export JAVA_PATH='${HOME}/Software/java/jdk1.6.0_24'

When I attempt to use ${JAVA_HOME} in a my ${PATH} javec is not found. To debug it, I tried a simple ls command:


and get the following error:

ls: ${HOME}/Software/java/jdk1.6.0_24/: No such file or directory

Using '~':

Trying to use '~' symbol as follows:

export JAVA_PATH='~/Software/java/jdk1.6.0_24'

the ls command results in the same error, however javac is found.

I prefer the '~' symbol anyway, but would like to understand why the ls command does not work for either, and why it seems as though ${HOME} is not being expanded.
Old 02-21-2011, 12:09 PM   #2
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,898

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
export JAVA_PATH='${HOME}/Software/java/jdk1.6.0_24'
The single quotes are your undoing. Use double quotes.

To see why, try this simple test in a terminal:
echo '${HOME}' note the single quotes
echo "${HOME}" with double quotes

The first echo gives ${HOME}
The second echo gives /home/<your-user-name>

You can read more about variable expansion and the use of single and double quotes in the bash man pages, Bash Beginners Guide, and the Advanced Bash Scripting Guide.

Last edited by bigrigdriver; 02-21-2011 at 12:21 PM.
1 members found this post helpful.
Old 02-21-2011, 12:13 PM   #3
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,211

Rep: Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612
Use double quotes.

Sorry -- took me a second to reply -- didn't see the previous poster's reply.
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash variable expansion problem JulianTosh Programming 2 09-06-2009 04:54 AM
variable expansion in bash coolhandluke1 Programming 4 01-09-2008 04:45 PM
Variable expansion in BASH champak Programming 5 11-26-2007 03:44 AM
trying to execute an expect script in .bashrc smaudlin Red Hat 2 01-02-2005 02:34 AM
bash script $n variable expansion cortez Programming 6 12-08-2003 05:03 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:37 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration