Latest LQ Deal: Linux Power User Bundle
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, 10: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, 11:09 AM   #2
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
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 11:21 AM.
1 members found this post helpful.
Old 02-21-2011, 11:13 AM   #3
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,213

Rep: Reputation: 1613Reputation: 1613Reputation: 1613Reputation: 1613Reputation: 1613Reputation: 1613Reputation: 1613Reputation: 1613Reputation: 1613Reputation: 1613Reputation: 1613
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 03:54 AM
variable expansion in bash coolhandluke1 Programming 4 01-09-2008 03:45 PM
Variable expansion in BASH champak Programming 5 11-26-2007 02:44 AM
trying to execute an expect script in .bashrc smaudlin Red Hat 2 01-02-2005 01:34 AM
bash script $n variable expansion cortez Programming 6 12-08-2003 04:03 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:37 AM.

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