3 ms·
"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 want
by 1vuio0pswjnm7 3y ago
"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".
- o11c 3y ago`$()` creates a subshell (a whole separate process) so is significantly slower than mere string manipulation. `$PWD` is always set accurately at startup (for both interactive and non-interactive shells) in bash, dash, zsh, ksh93, mksh, and busybox ash. So I'm really not sure where this assumption can be violated.