-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should rc unset PWD? #109
Comments
I agree that maintaining a correct $PWD is important since many programs out there rely on it.
So you mean rc should unset $PWD only when run as a login shell? In that case, you could simply add |
First, to clarify: I'm not asking that rc maintain a value for PWD [*], but that rc give its children no PWD. Second, I did truly mean to suggest rc unset PWD whenever it starts, not only as a login shell. Suppose the user's login shell is not rc, and they run an rc script that cd's: its subsequent children will inherit a PWD that disagrees with the cwd. [*] I would not object if rc maintained PWD using the POSIX shell's rules, but those rules are complicated and presumably not to everyone's liking; they're also easy enough to do in one's .rcrc for anybody who cares. However, I do not see much value maintaining a PWD with a different semantic than POSIX shell's, e.g., simply setting PWD to the result of getcwd(). That pathname will refer to the cwd, but not always as the pathname I want to see: I still use NFS file servers and automounters, and after (See also https://plan9.io/sys/doc/lexnames.html for more on the issues of directories with multiple names. IIUC, Plan 9 actually did solve this problem by having the OS remember a causal history for how the process got to its cwd; so Duff's rc never needed to maintain a pwd variable.) |
That makes sense. But in my case, I maintain $PWD using custom What could work instead, is for rc's builtin |
If anything I would prefer to generalize this. Making custom behavior for PWD feels like a one-off, and opens the door to other custom behaviors. What about |
@oliwer I hadn't consciously thought about subshells, but for clarity, I would not consider forking a subshell to be a moment @rakitzis I think I see what you mean about treating Maybe it'd be easier to evaluate the suggestion with an implementation in hand? Whatever you conclude, thank you for your time spent considering this issue. |
rc doesn't update PWD the way other shells do; I'm not asking that it do so. However, if an rc process inherits PWD and changes directory, any programs run under rc will inherit an incorrect PWD. I propose that an rc process simply unset PWD when it starts. (But only when it starts, so that a user might maintain PWD in custom cd/pushd/popd functions if they want to.)
Explanation: I have an ancient habit of preferring PWD over getcwd() in programs when I need a pathname for the working directory, because PWD typically contains or derives from previously-supplied user input, while getcwd()'s result can be different from anything the user wants to see or use. (In my programs, such pathnames are usually for diagnostic messages. I should probably always check if the PWD names the same directory as ".", but I'm sure I haven't done so consistently over the years. Anyhow I'd rather the environment variable be unset than incorrect.)
Note: I believe this is orthogonal to whether rc might maintain a $pwd variable, and with what semantics that has. (Drazen Borkovic's fork does this, but it looks like that fork leaves PWD alone, i.e., prone to have a stale value.)
The text was updated successfully, but these errors were encountered: