GNU bug report logs -
#34447
`pwd` doesn't show real working directory if directory is renamed by another session
Previous Next
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 34447 in the body.
You can then email your comments to 34447 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-coreutils <at> gnu.org
:
bug#34447
; Package
coreutils
.
(Tue, 12 Feb 2019 00:35:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Chris Wright <chriswright96 <at> hotmail.com>
:
New bug report received and forwarded. Copy sent to
bug-coreutils <at> gnu.org
.
(Tue, 12 Feb 2019 00:35:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi,
I found that if a session's working directory is renamed or moved, `pwd` doesn't show the real working directory.
Example:
Session 1:
```
~/ $ mkdir test
~/ $ cd test
~/test $ touch file
```
Session 2:
```
~/ $ mv test test_2
~/ $ mkdir test
~/ $ cd test
~/ $ touch file2
~/ $ ls
file2
~/ $
```
Session 1 (still running during session 2):
```
~/test $ ls
file
~/test $ pwd
/Users/<user>/test
~/test $ realpath file
/Users/<user>/test_2/file
~/test $ realpath nonExistenFile
/Users/<user>/test_2/nonExistenFile
```
It seems that `realpath` does show the updated path, but `pwd` doesn't
Tested on MacOS (10.14.3) and Ubuntu 16.04 / 18.04
Thanks,
Chris
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#34447
; Package
coreutils
.
(Fri, 22 Feb 2019 23:24:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 34447 <at> debbugs.gnu.org (full text, mbox):
tag 34447 + notabug
close 34447
thanks
Hello Chris,
Chris Wright wrote:
> I found that if a session's working directory is renamed or moved,
> `pwd` doesn't show the real working directory.
Thank you for your bug report. However I think the shell's built-in
pwd is being confused with the external pwd command. The shell
internal command has the behavior your describe, intentionally. The
external one in GNU Coreutils does not.
> ~/test $ pwd
> /Users/<user>/test
The above is using the internal shell builtin.
$ type pwd
pwd is a shell builtin
$ type -a pwd
pwd is a shell builtin
pwd is /bin/pwd
The bash shell built-in has this to say about the internal pwd.
$ help pwd
pwd: pwd [-LP]
Print the name of the current working directory.
Options:
-L print the value of $PWD if it names the current working
directory
-P print the physical directory, without any symbolic links
By default, `pwd' behaves as if `-L' were specified.
Therefore by default the shell's buitin pwd simply prints out the PWD
environment variable, which has not changed. This is to preserve the
"logical" (not physical) directory tree based upon how the process got
there, intentionally tracking how they got there not where they are.
They got there by the path stored in PWD.
I hate that behavior. But as with most things I was not consulted. :-}
In order to do what you want there are at least three options. One is
to use the external coreutils version. The idiom for forcing external
commands is using 'env' for it.
env pwd
Another is adding the -P option. This ignores PWD and returns the
physical path.
pwd -P
And the third (what I do) is to set the shell to always use physical
paths. Which is how it behaved before they added logical path
tracking in the PWD variable. I have this in my ~/.bashrc file.
set -o physical
Therefore I have closed this bug report for the purpose of triage of
the report in the coreutils tracker since this is really about bash
and not coreutils. However please do reply as discussion may
continue. We would love to continue the discussion.
Note that the coreutils 'pwd' defalts to -P, --physical unless -L,
--logical is given explicitly. And that the documentation for the
coreutils pwd is subtly different from the bash version:
'-L'
'--logical'
If the contents of the environment variable 'PWD' provide an
absolute name of the current directory with no '.' or '..'
components, but possibly with symbolic links, then output those
contents. Otherwise, fall back to default '-P' handling.
'-P'
'--physical'
Print a fully resolved name for the current directory. That is,
all components of the printed name will be actual directory
names—none will be symbolic links.
If '-L' and '-P' are both given, the last one takes precedence. If
neither option is given, then this implementation uses '-P' as the
default unless the 'POSIXLY_CORRECT' environment variable is set.
Due to shell aliases and built-in 'pwd' functions, using an unadorned
'pwd' interactively or in a script may get you different functionality
than that described here. Invoke it via 'env' (i.e., 'env pwd ...') to
avoid interference from the shell.
Hope this helps!
Bob
Added tag(s) notabug.
Request was from
Bob Proulx <bob <at> proulx.com>
to
control <at> debbugs.gnu.org
.
(Fri, 22 Feb 2019 23:24:02 GMT)
Full text and
rfc822 format available.
bug closed, send any further explanations to
34447 <at> debbugs.gnu.org and Chris Wright <chriswright96 <at> hotmail.com>
Request was from
Bob Proulx <bob <at> proulx.com>
to
control <at> debbugs.gnu.org
.
(Fri, 22 Feb 2019 23:24:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sat, 23 Mar 2019 11:24:04 GMT)
Full text and
rfc822 format available.
This bug report was last modified 5 years and 30 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.