Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: which: command not found
- X-seq: zsh-users 30405
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: "Mark J. Reed" <markjreed@xxxxxxxxx>
- Cc: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: which: command not found
- Date: Sat, 13 Dec 2025 08:27:21 +0000
- Archived-at: <https://zsh.org/users/30405>
- In-reply-to: <CAA=-s3z6DMCV1ScX7JXfogExG8iO4ak2tOqTZyh-OjeGe5M6xQ@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- Mail-followup-to: "Mark J. Reed" <markjreed@xxxxxxxxx>, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- References: <CAA=-s3xJ5iSmG1LESO_GGzAheJ3r7unYeOinYKJCMKquLWgP0Q@mail.gmail.com> <CAH+w=7YVTZap=TMwQMM699=cDEtFsG=g-J8uJh=XSbebz8DJSA@mail.gmail.com> <CAA=-s3z6DMCV1ScX7JXfogExG8iO4ak2tOqTZyh-OjeGe5M6xQ@mail.gmail.com>
2025-12-12 17:12:55 -0500, Mark J. Reed:
[...]
> So the answer is "because csh did it that way and that's where zsh got the
> 'which' command". Well, I guess that's why zsh also borrowed `whence` from
> ksh, which behaves more sensibly here.
which is the csh command (initially a csh script, see
https://github.com/dspinellis/unix-history-repo/blob/BSD-3/usr/ucb/which)
The Bourne shell equivalent is "type" (from SysVR2), the Korn
shell equivalent "whence" (you'll see than in zsh, "which" is an
alias for "whence -c", -c for csh), the POSIX equivalent "command
-V" (POSIX also specifies "type", but optional (XSI))
Note that command -V in mksh, zsh and bosh at least send the
"not found" to stdout. It's not cristal clear from the POSIX
specification
(https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/utilities/command.html)
whether that's right or not.
> I guess a consistent cross-shell approach here would be to use `type`,
> check the return code, and extract the pathname from the end of the message
> on success.
[...]
For the record, Bourne's "type" didn't return a non-zero exit
status upon "command not found", and sent that "command not
found" to stdout.
The FAQ entry is a bit misleading at the moment in that the only
other shell that I know that has "which" builtin is tcsh. Invoking
which in other shells would run whatever which command is found
in $PATH, and whatever that does depends on that which
implementation.
If it's the original which csh script (as it would still be on
some commercial Unices), the "not found" will be sent on stdout.
The which here on Ubuntu 24.04 doesn't report any error upon not
found.
See
https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then
for more of the gory details.
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author