[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: |
Sat, 20 Jun 2020 14:02:07 -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 1:28 PM, Lawrence Velázquez wrote:
> Here's something fun though:
>
> $ PROMPT_COMMAND='cd .'
> $ readlink /tmp
> private/tmp
> $ mkdir /tmp/old
> $ cd /tmp/old
> $ echo "$PWD"
> /tmp/old
> $ mv /tmp/old /tmp/new
> $ echo "$PWD"
> /private/tmp/new
>
> Not wrong, but maybe unexpected to some.
It's a way to make sure PWD is correct after a `cd'. Without options, `cd'
canonicalizes its pathname argument in the way POSIX describes in
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/cd.html#tag_20_14
That converts it to /tmp/old ("." -> "/tmp/old/." -> "/tmp/old")
Since chdir to "/tmp/old" fails, bash falls back to chdir to ".", which
succeeds, and then recanonicalizes PWD to the true directory pathname, as
would be returned by `pwd -P'.
--
``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/
Re: Bug on bash shell - $PWD (and consequentely prompt) not updated while renaming current folder., Chet Ramey, 2020/06/20