bug-bash
[Top][All Lists]
Advanced

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

Re: cd: null directory


From: Chet Ramey
Subject: Re: cd: null directory
Date: Thu, 31 Jul 2025 09:13:50 -0400
User-agent: Mozilla Thunderbird

On 7/30/25 5:15 PM, Robert Elz wrote:
     Date:        Wed, 30 Jul 2025 09:31:52 -0600
     From:        Stan Marsh <gazelle@xmission.com>
     Message-ID:  <E1uh8mW-0000000EYGT-0mPc@shell.xmission.com>

   | I wonder why "" was previously special-cased.

Once upon a time, chdir("") would have acted the same as chdir(".")
because in the kernel, the pathname lookup would see that this is
a relative path (doesn't start with '/') so the path lookup starts
at "." then it would extract the next pathname segment - but as there
isn't one, the pathname given has ended.   We're currently at "."
when the search ends, all good, use that.

That is essentially what happens when you use the POSIX algorithm as
provided in

https://pubs.opengroup.org/onlinepubs/9799919799/utilities/cd.html

except you run through $CDPATH first. You append the directory name
argument to $PWD, remove a trailing slash, and you're left with $PWD.

So if you want to make `cd ""' an error, you have to call it out
explicitly, or special-case it throughout the description.

--
``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/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


reply via email to

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