"Sometimes people then write shell scripts and other code that assumes '$PWD' is accurate if it's present, which is not necessarily true."
Unless one only wants the current directory name at the start of a script why not just use the builtin pwd command, $(pwd). Or getcwd() if it's "other code".
Unless one only wants the current directory name at the start of a script why not just use the builtin pwd command, $(pwd). Or getcwd() if it's "other code".