[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bug in pwd on Mandrake Linux 9.2
From: |
Seán McGarraghy |
Subject: |
Re: bug in pwd on Mandrake Linux 9.2 |
Date: |
Sat, 5 Mar 2005 13:45:29 +0000 (GMT) |
Bob,
Thanks very much for your comprehensive reply, and the explanation: I am now
clear on how the builtin works.
Re your question: I got the version number from the man page for pwd. It
said it was GNU pwd and gave address@hidden as the contact email.
Apologies for raising as a bug something that is actually reasonable
behaviour!
Thanks again,
Sean
On Fri, 4 Mar 2005, Bob Proulx wrote:
> Seán McGarraghy wrote:
> > I am running Mandrake Linux 9.2, the version of pwd is
> >
> > pwd 5.0 March 2003
>
> How did you obtain that version number from pwd? (I think it is very
> strange.)
>
> > I found the following behaviour (running as root at the command line)
> >
> > address@hidden linux32]# pwd
> > /usr/local/lindoapi/bin/linux32
> > address@hidden linux32]# mv ../../../lindoapi ../../../lindoapi3.0
> > address@hidden linux32]# pwd
> > /usr/local/lindoapi/bin/linux32
> > address@hidden linux32]# ls -al /usr/local/lin*
> > drwxr-xr-x 10 root root 368 Mar 4 17:20 lindoapi3.0/
> >
> > That is, I renamed a directory further up the path of the current working
> > directory, but pwd didn't catch this (although ls shows it happened).
>
> Generally that is true. The default behavior of most modern shells is
> to report the logical path and not the physical path.
>
> > I don't know if this bug is still in later versions, but I thought
> > you should know. Its severity is not too big.
>
> Thank you for reporting this. As has been said, many eyes make all
> bugs known. However you should know that 'pwd' is a shell builtin in
> most shells. In bash, for example:
>
> type pwd
> pwd is a shell builtin
>
> Therefore when you type in 'pwd' you are not getting an external pwd
> such as the GNU pwd usually installed at /bin/pwd but are instead
> getting your shell's built in pwd. Therefore this is not a GNU
> coreutils thing but a shell thing.
>
> In the case of the shell it usually tracks the PWD environment
> variable by logical path and not by physical path. The behavior you
> are seeing is actually a feature of the shell. It does this so that
> the user does not notice symbolic links in the path. Here is an
> example.
>
> $ mkdir /tmp/foo
> $ ln -s foo /tmp/bar
> $ cd /tmp/bar
> $ pwd
> /tmp/bar
> $ /bin/pwd
> /tmp/foo
>
> Even though the shell reported the present working directry as
> /tmp/bar it only knew that because it tracked how we got there. That
> is the logical path. We got there through the symlink and so it
> reported that value. But we were really in /tmp/bar because of the
> symlink. The /bin/pwd program did not know about the tracking of the
> logical path. It called the systems getcwd() routine and reported the
> real physical path.
>
> In GNU bash the 'set -o physical' option turns off this logical path
> tracking of the shell. Setting that option with your example would
> report the new name of the physical present working directory.
>
> In bash:
>
> $ set -o physical
> $ mkdir /tmp/foo
> $ cd /tmp/foo
> $ mv /tmp/foo /tmp/bar
> $ pwd
> $ /tmp/bar
>
> Hope that helps to explain this.
>
> Bob
>
--
Dr Seán McGarraghy
Dept of Management Information Systems
University College Dublin
Belfield, Dublin 4, Ireland.
email: address@hidden
tel +353 1 716 4734, fax +353 1 716 4783