Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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'd like to save my current directory into a value.

I do it like this

dir=`dirname $0`

But when I now change the directory and use this variable, it seems that the expression gets evaluated anew.

Do you know how I can store it's value in the variable, not the expression itself?

share|improve this question
up vote 1 down vote accepted

This looks ok to me. The expression will not get evaluated every time. Try echo $dir to see the value of the dir variable.

share|improve this answer
The expression evaluated to .. I've now changed the command to pwd. – user36938 Apr 18 '11 at 8:01
What might also be useful sometimes is readlink -f - Don't be fooled by the name/man page, it works on files/directories. – PriceChild Apr 18 '11 at 8:30

You must log in to answer this question.