zsh-workers
 help / color / mirror / code / Atom feed
* command cd doesn't work on some builds of zsh
@ 2024-02-13  9:54 Ajeet D'Souza
  2024-02-13 10:05 ` Andreas Kähäri
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Ajeet D'Souza @ 2024-02-13  9:54 UTC (permalink / raw)
  To: zsh-workers

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

Hi, I found inconsistent behaviour of the command builtin in some builds on
zsh.

On Fedora 39:
*$ zsh --version*
zsh 5.9 (x86_64-redhat-linux-gnu)
*$ zsh -c 'command cd'*

On Debian 10:
*$ zsh --version*
zsh 5.9 (x86_64-unknown-linux-gnu)
*$ zsh -c 'command cd'*
zsh:1: command not found: cd

According to the manual, command cd should work:

> Run command with args suppressing the normal shell function lookup. *Only
> builtin commands* or commands found in the PATH are executed.


Any idea why different builds on zsh produce different outcomes here?

Thanks,
Ajeet

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

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

* Re: command cd doesn't work on some builds of zsh
  2024-02-13  9:54 command cd doesn't work on some builds of zsh Ajeet D'Souza
@ 2024-02-13 10:05 ` Andreas Kähäri
  2024-02-13 11:48   ` Ajeet D'Souza
  2024-02-13 10:48 ` Peter Stephenson
  2024-02-13 14:25 ` Lawrence Velázquez
  2 siblings, 1 reply; 6+ messages in thread
From: Andreas Kähäri @ 2024-02-13 10:05 UTC (permalink / raw)
  To: Ajeet D'Souza; +Cc: zsh-workers

On Tue, Feb 13, 2024 at 03:24:22PM +0530, Ajeet D'Souza wrote:
> Hi, I found inconsistent behaviour of the command builtin in some builds on
> zsh.
> 
> On Fedora 39:
> *$ zsh --version*
> zsh 5.9 (x86_64-redhat-linux-gnu)
> *$ zsh -c 'command cd'*
> 
> On Debian 10:
> *$ zsh --version*
> zsh 5.9 (x86_64-unknown-linux-gnu)
> *$ zsh -c 'command cd'*
> zsh:1: command not found: cd
> 
> According to the manual, command cd should work:
> 
> > Run command with args suppressing the normal shell function lookup. *Only
> > builtin commands* or commands found in the PATH are executed.
> 
> 
> Any idea why different builds on zsh produce different outcomes here?

Is there in fact an external cd command on the Fedora system?  Is the
POSIX_BUILTINS zsh shell option set by default on the Fedora system?

-- 
Andreas (Kusalananda) Kähäri
Uppsala, Sweden

.


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

* Re: command cd doesn't work on some builds of zsh
  2024-02-13  9:54 command cd doesn't work on some builds of zsh Ajeet D'Souza
  2024-02-13 10:05 ` Andreas Kähäri
@ 2024-02-13 10:48 ` Peter Stephenson
  2024-02-13 14:25 ` Lawrence Velázquez
  2 siblings, 0 replies; 6+ messages in thread
From: Peter Stephenson @ 2024-02-13 10:48 UTC (permalink / raw)
  To: Ajeet D'Souza, zsh-workers

> On 13/02/2024 09:54 GMT Ajeet D'Souza <98ajeet@gmail.com> wrote:
> 
> 
> Hi, I found inconsistent behaviour of the command builtin in some builds on zsh.
> 
> On Fedora 39:
> $ zsh --version
> zsh 5.9 (x86_64-redhat-linux-gnu)
> $ zsh -c 'command cd'
> 
> On Debian 10:
> $ zsh --version
> zsh 5.9 (x86_64-unknown-linux-gnu)
> $ zsh -c 'command cd'
> zsh:1: command not found: cd
> 
> According to the manual, command cd should work:
> > Run command with args suppressing the normal shell function lookup. Only builtin commands or commands found in the PATH are executed.
> 
> Any idea why different builds on zsh produce different outcomes here?

It's likely to be a difference in the setting of the POSIX_BUILTINS
option between the two cases.  By default, with it off, "command"
doesn't apply to builtins --- you'd need to use "builtin cd" in
vanilla zsh to ensure it was running the builtin command.
With POSIX_BUILTINS set it'll find cd.

pws


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

* Re: command cd doesn't work on some builds of zsh
  2024-02-13 10:05 ` Andreas Kähäri
@ 2024-02-13 11:48   ` Ajeet D'Souza
  2024-02-13 12:02     ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Ajeet D'Souza @ 2024-02-13 11:48 UTC (permalink / raw)
  To: zsh-workers

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

You're right, Fedora does have a cd binary which is why this works:

*$ which cd*
/usr/bin/cd

However, this still seems like inconsistent behaviour:

*$ /usr/bin/cd "foo"*
# this will not change directories, because a binary cannot change the CWD
of its parent process
*$ command cd "foo"*
# this throws an error on systems without a cd binary, but it actually
calls the shell builtin and changes the CWD

Also, since the manpage mentions that command is supposed to invoke shell
builtins, why does this command fail without POSIX_BUILTINS being set? Is cd
not considered a builtin otherwise?

On Tue, Feb 13, 2024 at 3:35 PM Andreas Kähäri <andreas.kahari@abc.se>
wrote:

> On Tue, Feb 13, 2024 at 03:24:22PM +0530, Ajeet D'Souza wrote:
> > Hi, I found inconsistent behaviour of the command builtin in some builds
> on
> > zsh.
> >
> > On Fedora 39:
> > *$ zsh --version*
> > zsh 5.9 (x86_64-redhat-linux-gnu)
> > *$ zsh -c 'command cd'*
> >
> > On Debian 10:
> > *$ zsh --version*
> > zsh 5.9 (x86_64-unknown-linux-gnu)
> > *$ zsh -c 'command cd'*
> > zsh:1: command not found: cd
> >
> > According to the manual, command cd should work:
> >
> > > Run command with args suppressing the normal shell function lookup.
> *Only
> > > builtin commands* or commands found in the PATH are executed.
> >
> >
> > Any idea why different builds on zsh produce different outcomes here?
>
> Is there in fact an external cd command on the Fedora system?  Is the
> POSIX_BUILTINS zsh shell option set by default on the Fedora system?
>
> --
> Andreas (Kusalananda) Kähäri
> Uppsala, Sweden
>
> .
>

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

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

* Re: command cd doesn't work on some builds of zsh
  2024-02-13 11:48   ` Ajeet D'Souza
@ 2024-02-13 12:02     ` Peter Stephenson
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Stephenson @ 2024-02-13 12:02 UTC (permalink / raw)
  To: Ajeet D'Souza, zsh-workers

On 13/02/2024 11:48 GMT Ajeet D'Souza <98ajeet@gmail.com> wrote:
> Also, since the manpage mentions that command is supposed to invoke
> shell builtins, why does this command fail
> without POSIX_BUILTINS being set? Is cd not considered a builtin
> otherwise?

No, builtins are *only* invoked by "command" when POSIX_BUILTIN is set.
(As I said, native zsh uses "builtin", not "command", for restricting to
builtins.)  The manual page is clear about this:


command [ -pvV ] simple command

The simple command argument is taken as an external command instead of
a function or builtin and is executed. If the POSIX_BUILTINS option  is
set,  builtins  will also be executed but certain special properties of
them are suppressed. The -p flag causes a default path to  be  searched
instead  of  that  in  $path.  With  the -v flag, command is similar to
whence and with -V, it is equivalent to whence -v.


In your case the zsh "builtin" command is more useful, because as you
note you quite definitely don't want to execute the external command
"cd".

pws


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

* Re: command cd doesn't work on some builds of zsh
  2024-02-13  9:54 command cd doesn't work on some builds of zsh Ajeet D'Souza
  2024-02-13 10:05 ` Andreas Kähäri
  2024-02-13 10:48 ` Peter Stephenson
@ 2024-02-13 14:25 ` Lawrence Velázquez
  2 siblings, 0 replies; 6+ messages in thread
From: Lawrence Velázquez @ 2024-02-13 14:25 UTC (permalink / raw)
  To: Ajeet D'Souza; +Cc: zsh-workers

On Tue, Feb 13, 2024, at 4:54 AM, Ajeet D'Souza wrote:
> According to the manual, command cd should work:
>> Run command with args suppressing the normal shell function lookup. *Only builtin commands* or commands found in the PATH are executed.

This is from the bash man page.

-- 
vq


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

end of thread, other threads:[~2024-02-13 14:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-13  9:54 command cd doesn't work on some builds of zsh Ajeet D'Souza
2024-02-13 10:05 ` Andreas Kähäri
2024-02-13 11:48   ` Ajeet D'Souza
2024-02-13 12:02     ` Peter Stephenson
2024-02-13 10:48 ` Peter Stephenson
2024-02-13 14:25 ` 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).