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

Re: BUG: Shell builtin `which` prints non-existent commands to stdout



2018-09-24 13:51:24 +0100, Peter Stephenson:
> On Mon, 24 Sep 2018 14:29:33 +0200
[...]
> +  The original reason for this is that this behaviour is inherited
> +  from the C shell (csh), where `tt(which)' itself orignated.  So
> +  it has been in zsh a very long time, and it is now a feature.
> +  (It would be possible to change this in emulation modes; however.
> +  so far this possibility has been seen has more of an additional
> +  confusion than a help.)
[...]

csh had no "which" (tcsh has a which builtin), but there was a
"which" csh script added to 3BSD 1980 that was looking up
commands in $PATH and in the aliases defined through ~/.cshrc.
https://github.com/dspinellis/unix-history-repo/blob/BSD-3/usr/ucb/which

There's no easy way to write something to stderr in csh, so it's
not surprising that that script didn't.

In any case, the "command not found" can be seen as the normal
output of which, it is *the* information that it is returning
for that command.

zsh is not the only shell for which "type not-a-command" doesn't
output "command not found" on stderr. The Bourne shell, pdksh
and derivatives and ash-based shells do as well.

-- 
Stephane



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