Closed adonovan closed 1 week ago
Similar Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Change https://go.dev/cl/609395 mentions this issue: os/exec: document interaction of Dir, PWD, os.Getwd and C
The interaction of exec.Cmd and os.Getwd is rather subtle: the working directory of a POSIX process is represented by a file descriptor, not a string, so C's getcwd will always return a real (symlink-free) path. By contrast, Go's os.Getwd will return the value of $PWD if it is an alias for the real path. (It does not do this for ancestors or other directories: it won't return $PWD/foo if that is an alias for getcwd, for example.)
exec.Cmd
sets thePWD
variable implicitly in order to makeos.Getwd
, and similar functions such as GNU C'sget_current_dir_name
, work this way--but it only does so in certain circumstances.We should document the subtleties of this issue so that users of os/exec and os.Getwd don't get confused (as I did in https://github.com/golang/go/issues/67757).