Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: command cd doesn't work on some builds of zsh



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@xxxxxx> 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

.


Messages sorted by: Reverse Date, Date, Thread, Author