0

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 1

1

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

2
  • The expression evaluated to .. I've now changed the command to pwd.
    – user36938
    Apr 18, 2011 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.
    – Pricey
    Apr 18, 2011 at 8:30

You must log in to answer this question.