# Shell: Save value in a variable, not the command

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? - ## 1 Answer This looks ok to me. The expression will not get evaluated every time. Try echo$dir to see the value of the dir variable.

-
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