zsh-workers
 help / color / mirror / code / Atom feed
* cd with empty argument does not conform to POSIX.1-2024 (Was: inherit OLDPWD from environment variable)
@ 2024-07-23  3:07 Lawrence Velázquez
  2024-07-23 15:47 ` Mark J. Reed
  0 siblings, 1 reply; 5+ messages in thread
From: Lawrence Velázquez @ 2024-07-23  3:07 UTC (permalink / raw)
  To: zsh-workers

On Fri, Jul 19, 2024, at 10:46 PM, Lawrence Velázquez wrote:
> If we're going to begin importing OLDPWD from the environment, we
> might as well align with other shells for consistency, which means
> accepting a zero-length value as is.

Speaking of zero-length values vis-à-vis cd:

	% cd ""

The current behavior is to do nothing and exit with a zero status.
This is allowed by POSIX.1-2018 [1]:

	If _directory_ is an empty string, the results are unspecified.

However, it is not allowed by the newly released POSIX.1-2024 [2]:

	If _directory_ is an empty string, _cd_ shall write a
	diagnostic message to standard error and exit with non-zero
	status.

I don't have strong feelings about changing the default behavior,
but it would be useful to update POSIX_CD at least (and thus ksh/sh
emulation).

[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/cd.html
[2]: https://pubs.opengroup.org/onlinepubs/9799919799/utilities/cd.html

-- 
vq


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: cd with empty argument does not conform to POSIX.1-2024 (Was: inherit OLDPWD from environment variable)
  2024-07-23  3:07 cd with empty argument does not conform to POSIX.1-2024 (Was: inherit OLDPWD from environment variable) Lawrence Velázquez
@ 2024-07-23 15:47 ` Mark J. Reed
  2024-07-23 15:56   ` zeurkous
                     ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Mark J. Reed @ 2024-07-23 15:47 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1467 bytes --]

> The current behavior is to do nothing and exit with a zero status.

For comparison purposes, note that this is also the current behavior of
bash, even in POSIX mode.  Also dash. Whereas ksh does report an error
("bad directory") and exit with status 1.


On Mon, Jul 22, 2024 at 11:08 PM Lawrence Velázquez <larryv@zsh.org> wrote:

> On Fri, Jul 19, 2024, at 10:46 PM, Lawrence Velázquez wrote:
> > If we're going to begin importing OLDPWD from the environment, we
> > might as well align with other shells for consistency, which means
> > accepting a zero-length value as is.
>
> Speaking of zero-length values vis-à-vis cd:
>
>         % cd ""
>
> The current behavior is to do nothing and exit with a zero status.
> This is allowed by POSIX.1-2018 [1]:
>
>         If _directory_ is an empty string, the results are unspecified.
>
> However, it is not allowed by the newly released POSIX.1-2024 [2]:
>
>         If _directory_ is an empty string, _cd_ shall write a
>         diagnostic message to standard error and exit with non-zero
>         status.
>
> I don't have strong feelings about changing the default behavior,
> but it would be useful to update POSIX_CD at least (and thus ksh/sh
> emulation).
>
> [1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/cd.html
> [2]: https://pubs.opengroup.org/onlinepubs/9799919799/utilities/cd.html
>
> --
> vq
>
>

-- 
Mark J. Reed <markjreed@gmail.com>

[-- Attachment #2: Type: text/html, Size: 2312 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: Re: cd with empty argument does not conform to POSIX.1-2024 (Was: inherit OLDPWD from environment variable)
  2024-07-23 15:47 ` Mark J. Reed
@ 2024-07-23 15:56   ` zeurkous
       [not found]   ` <669fd732.630a0220.d347b.bce7SMTPIN_ADDED_BROKEN@mx.google.com>
  2024-07-23 21:09   ` Lawrence Velázquez
  2 siblings, 0 replies; 5+ messages in thread
From: zeurkous @ 2024-07-23 15:56 UTC (permalink / raw)
  To: Mark J. Reed, zsh-workers

Haai,

On Tue, 23 Jul 2024 11:47:48 -0400, "Mark J. Reed" <markjreed@gmail.com> wrote:
> --000000000000218e21061dec1638
> Content-Type: text/plain; charset="UTF-8"
> Content-Transfer-Encoding: quoted-printable
>
>> The current behavior is to do nothing and exit with a zero status.
>
> For comparison purposes, note that this is also the current behavior of
> bash, even in POSIX mode.  Also dash. Whereas ksh does report an error
> ("bad directory") and exit with status 1.

For consistency: me's in favour of scrapping the lax behaviour; after
all--

 0% ls ''
 ls: : No such file or directory
 1% mkdir ''
 mkdir: : No such file or directory
 1% echo blaat >''
 zsh:1: no such file or directory: 
 1%

One could argue that UNIX should allow for empty file names (after all:
the only real technical restriction here is that a nul character cannot
appear within) but fact is that it doesn't, and the behaviour of `cd'
should reflect that prohibition.

Also per the above: instead of "bad directory", mefavours the standard 
error string, but that's less important.

Me's not sure how clever zsh is being here (don't have time to check the
code), but to me, just letting chdir(2) handle it all seems to be the
obvious solution.

        --zeurkous.

-- 
Friggin' Machines!


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Re: cd with empty argument does not conform to POSIX.1-2024 (Was: inherit OLDPWD from environment variable)
       [not found]   ` <669fd732.630a0220.d347b.bce7SMTPIN_ADDED_BROKEN@mx.google.com>
@ 2024-07-23 16:31     ` Mark J. Reed
  0 siblings, 0 replies; 5+ messages in thread
From: Mark J. Reed @ 2024-07-23 16:31 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1876 bytes --]

> Also per the above: instead of "bad directory", mefavours the standard
error string, but that's less important.
>  just letting chdir(2) handle it all seems to be the
obvious solution.

If you hand the empty string to chdir(2), it returns the expected ENOENT,
at least on macOS and Linux. I agree that just sticking with the system
error string seems best.


On Tue, Jul 23, 2024 at 12:15 PM <zeurkous@blaatscaahp.org> wrote:

> Haai,
>
> On Tue, 23 Jul 2024 11:47:48 -0400, "Mark J. Reed" <markjreed@gmail.com>
> wrote:
> > --000000000000218e21061dec1638
> > Content-Type: text/plain; charset="UTF-8"
> > Content-Transfer-Encoding: quoted-printable
> >
> >> The current behavior is to do nothing and exit with a zero status.
> >
> > For comparison purposes, note that this is also the current behavior of
> > bash, even in POSIX mode.  Also dash. Whereas ksh does report an error
> > ("bad directory") and exit with status 1.
>
> For consistency: me's in favour of scrapping the lax behaviour; after
> all--
>
>  0% ls ''
>  ls: : No such file or directory
>  1% mkdir ''
>  mkdir: : No such file or directory
>  1% echo blaat >''
>  zsh:1: no such file or directory:
>  1%
>
> One could argue that UNIX should allow for empty file names (after all:
> the only real technical restriction here is that a nul character cannot
> appear within) but fact is that it doesn't, and the behaviour of `cd'
> should reflect that prohibition.
>
> Also per the above: instead of "bad directory", mefavours the standard
> error string, but that's less important.
>
> Me's not sure how clever zsh is being here (don't have time to check the
> code), but to me, just letting chdir(2) handle it all seems to be the
> obvious solution.
>
>         --zeurkous.
>
> --
> Friggin' Machines!
>


-- 
Mark J. Reed <markjreed@gmail.com>

[-- Attachment #2: Type: text/html, Size: 2696 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: cd with empty argument does not conform to POSIX.1-2024 (Was: inherit OLDPWD from environment variable)
  2024-07-23 15:47 ` Mark J. Reed
  2024-07-23 15:56   ` zeurkous
       [not found]   ` <669fd732.630a0220.d347b.bce7SMTPIN_ADDED_BROKEN@mx.google.com>
@ 2024-07-23 21:09   ` Lawrence Velázquez
  2 siblings, 0 replies; 5+ messages in thread
From: Lawrence Velázquez @ 2024-07-23 21:09 UTC (permalink / raw)
  To: zsh-workers

On Tue, Jul 23, 2024, at 11:47 AM, Mark J. Reed wrote:
>> The current behavior is to do nothing and exit with a zero status.
>
> For comparison purposes, note that this is also the current behavior of 
> bash, even in POSIX mode.

This will be fixed in the next release; the development version [*]
already errors out:

	% ./bash -c 'echo "$BASH_VERSION"; cd ""'
	5.3.0(6)-alpha
	./bash: line 1: cd: null directory

[*]: https://git.savannah.gnu.org/cgit/bash.git/tree/builtins/cd.def?h=devel&id=6c703092759ace29263ea96374e18412c59acc7f#n333


> Also dash.

Presumably a future release will fix this, given dash's explicit
goal of POSIX conformance.


> Whereas ksh does report an error  ("bad directory") and exit
> with status 1.

This bolsters the argument for, at a minimum, updating ksh/sh
emulation via POSIX_CD, as does the fact that the Solaris 10
Bourne shell fails too.


-- 
vq


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-07-23 21:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-23  3:07 cd with empty argument does not conform to POSIX.1-2024 (Was: inherit OLDPWD from environment variable) Lawrence Velázquez
2024-07-23 15:47 ` Mark J. Reed
2024-07-23 15:56   ` zeurkous
     [not found]   ` <669fd732.630a0220.d347b.bce7SMTPIN_ADDED_BROKEN@mx.google.com>
2024-07-23 16:31     ` Mark J. Reed
2024-07-23 21:09   ` Lawrence Velázquez

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).