[Top][All Lists]

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

Re: cd "" return value

From: Chet Ramey
Subject: Re: cd "" return value
Date: Tue, 19 Mar 2019 10:33:59 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.5.3

On 3/19/19 4:21 AM, address@hidden wrote:
> Good morning,  
> In GNU bash, version 5.0.2(1)-release (x86_64-pc-linux-gnu):
> The command cd "" is successful but cd -P "" fails.
> This is inconsistent and not evident in man bash.
> Expected is that cd "$(mktemp -d)" returns error if mktemp fails.

This is a consequence of the pathname canonicalization that takes place
using the supplied argument, because the -L option is the default. Pretty
much every POSIX-conformant shell behaves like this.

>       The  return  value  is  true  if  the directory was successfully
>       changed; false otherwise.

After canonicalization, it's equivalent to cd $PWD, which is successful.
The -P option forces an attempt to cd to "" directly, which fails because
chdir(2) fails with ENOENT when its argument is the empty string.

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

reply via email to

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