Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to know how to set up an environment variable that stores other environment variable but these environment variables doesn't gets expanded when I echo instead if I use eval echo then it should expand.

Like i want to have echo $TEST_HOME should result in /Users/krysto/$PATH/$DATA_DIR

share|improve this question
up vote 1 down vote accepted

Create TEST_HOME using single-quotes to prevent bash expansion:

$ TEST_HOME='/Users/krysto/$MYPATH/$DATA_DIR'
$ echo $TEST_HOME

Then, one can use eval to expand it.  As an example:

$ MYPATH=dir1/dir2
$ DATA_DIR=data/dir
$ eval echo $TEST_HOME

A couple of notes: The convention is that the important system variables, like PATH or HOME, are all upper-case. If you want to avoid overwriting one of them, make your variables lower-case. In particular, overriding PATH could leave the shell that you are in largely non-functional.

share|improve this answer

Just escape the variables (makes no diffirence if local or env), e.g.

> test="echo something"
> test1="\$test"
> echo $test1
> eval $test1
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.