IMHO you can not set the PWD parameter. It is set by the shell and contains: “The present working directory set by the **cd **command”. And that is (and should be) the only way to alter the PWD parameter.
The man page on the system differs from the one in my manual. It says:
“This variable shall represent an absolute pathname of the current working directory. Assignments to this variable may be ignored unless the value is an absolute pathname of the current working directory and there are no filename components of dot or dot-dot”.
Hm, sounds strange to me, I read this as: it can be assigned as it is what it already is.
My conclusion, use cd to change your working directory (and PWD will change to reflect this).
Well, the text file was just an example of relative reference. In my actual case I have several scripts in a directory structure calling each other. Always calling with an absolute path makes things inflexible, and the long pathnames messes up the code.
I could of course prepend the output of dirname $0 to every reference in all scripts. I was just hoping there was a way to change the environment to accomplish that automatically.
I am not sure I understand completely what your lay out is (in fact I am pretty sure I don’t ), but in a (may be) similar case, I start every script with setting variables to the different directories where scripts are:
Yes it does. That will most likely be the way I do it.
Though I still think an option to the shell telling it to execute a command file from where it resides (as opposed to where it was called from) would be a useful feature. Any shell developers reading this?
well… correct me if I’m wrong but doesn’t basename strip leading directory path from it’s argument, so that:
would simply become:
which of course would work as long as the calling shell script and the called program reside in the same directory (as you said). But if called from another directory, as was my original intent, program would not be found, right? :\