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?

link|improve this question

feedback

1 Answer

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.

link|improve this answer
The expression evaluated to .. I've now changed the command to pwd. – New Talk 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
feedback

Your Answer

 
or
required, but never shown

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