Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer


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