Quote:
|
What is your concern with using $PWD? If concerned about someone exporting variables to an incorrect value, you could always use $(pwd) to set the value of PWD.
|
Because if you write scripts using absolute paths that are not depending on a) where the script starts from, or b) from cd'ing somewhere inside the script, $PWD is irrelevant.
ta0kira has it right: to return the absolute path of a filename that is originally given with a relative path:
for example you are at a bash prompt in /dir1/dir2/dir3/dir4
and the file is /dir1/dir2/file1
ABSOLUTE_DIR=$(dirname $(readlink -f ../../dir2/file1))