[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug on bash shell - $PWD (and consequentely prompt) not updated whil

From: Chet Ramey
Subject: Re: Bug on bash shell - $PWD (and consequentely prompt) not updated while renaming current folder.
Date: Sun, 21 Jun 2020 12:26:03 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.8.1

On 6/20/20 7:32 PM, Ángel wrote:

> The hidden command "cd ." changed us into a completely different
> directory. Perhaps unexpected for the user (why did the bash version
> changed completely in the middle of a test run??).
> Reading the above POSIX link, I would expect cd -P . not to have such
> side effect.
> I read the instructions:
>> 6. Set curpath to the directory operand.
>> 7. If the -P option is in effect, proceed to step 10. If curpath does
>> not begin with a <slash> character, set curpath to the string formed
>> by the concatenation of the value of PWD, a <slash> character if the
>> value of PWD did not end with a <slash> character, and curpath.
>> 10. The cd utility shall then perform actions equivalent to the
>> chdir() function called with curpath as the path argument.
> (trimmed for clarity)
> And would expect "cd -P ." to perform the equivalent of chdir("."),
> which should always leave you on the same folder you are in.

It does. The folder is the same, though its name might have changed if
the rename happens out from underneath the shell.

> However, it appears that it performs the concatenation even when -P is
> in effect.

How do you conclude this?

What it does do is part of step 10, which you trimmed.

"If the -P option is in effect, the PWD environment variable shall be set
to the string that would be output by pwd -P."

In the examples we've been using so far, what happens is that the
chdir(".") occurs, $PWD is discarded since it wasn't what `pwd -P' would
have output, the current working directory gets rebuilt using the
equivalent of getcwd(), and PWD is set to that.

Even if you don't rename the directory, $PWD can change in the presence of
symlinks, since `pwd -P' produces a physical path that doesn't contain any

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]