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    c...@case.edu    http://tiswww.cwru.edu/~chet/

Reply via email to