Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
BUG: Shell builtin `which` prints non-existent commands to stdout
- X-seq: zsh-workers 43523
- From: Klaus Alexander Seistrup <klaus@xxxxxxxxxxx>
- To: Zsh Workers <zsh-workers@xxxxxxx>
- Subject: BUG: Shell builtin `which` prints non-existent commands to stdout
- Date: Mon, 24 Sep 2018 10:00:31 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seistrup.dk; s=dkim; h=date:from:to:subject:message-id:mime-version:content-disposition :content-transfer-encoding:organization:scuttlebutt:openalias:vcard :openpgp:user-agent; bh=t3kVP+cl0F7WUuk1hIZLoP9bzC+yq28Fpo0sSPbN/Ic=; b=HZeByeqCxD8LZueh52Pzmp0Y9AZjzTuzjp/96EN9ZE3oE72LuqeZA+pF2qXlwRszeJ y6btKM1wkjHAKcKK2XY45FTsfs5KGS/upIjnwS58jJPxH+SlxNR39qx+DMrg4vg0J0FI iQU4pAi71C18KmQEfPaGUGSzAiv43nQdH8/Uu/9NxlOPr7sb0msXBIuTCqRfYBwUam+/ rs7Kl79/vED4Bs8FfCc/P97H4PnzhAmugYIc2t0HM8+0SxEpLIJl81qyVrOUH9JkfotT E4y5+ZxDPzaqOBQM4XRyPVkl2g0JIIWmA1WrooA/1fnYcLBKgmGfOyBnxT4Em1iJfDZu gY5Q==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- Openalias: klaus.seistrup.dk
- Openpgp: id=D2620A739DBE0D41216ADF2705483F10A54192F8; uri=https://klaus.seistrup.dk/pubkey.asc; preference=sign
- Organization: Bornmesh, Bornholm, Denmark
- Scuttlebutt: @dBQlwh9Gtr3i5YMOGtIOKtGNVepeu+nyb6KGl1vtOcM=.ed25519
- Vcard: uuid=d4790855-a33a-5757-8154-8ecce7a04f9d; uri=https://klaus.seistrup.dk/vcard.vcf
TL;DR: When `which` does not find a command it prints the error to
standard output instead of standard error. Exit code is set correctly,
though, and error messages about ‘bad options’ are sent to standard
error as expected.
In a nutshell:
```sh
$ echo $SHELL # can you tell us a little about yourself?
/usr/bin/zsh # ✓
$ type which # please tell us what you know about `which`
which is a shell builtin # ✓
$ which vi # can you find `vi`?
/usr/bin/vi # ✓
$ echo $? # show us the exit code
0 # ✓
$ which nxcmd # tell me about a non-existent command
nxcmd not found # ✓
$ echo $? # and let us see the exit code
1 # ✓
$ which nxcmd 2>/dev/null # this command ought to keep `which` silent, but …
nxcmd not found # ✗
$ which nxcmd >/dev/null # … the error message is sent to stdout
$ # ✗
$ which -T # let's try an unrecognized option
which: bad option: -T # ✓
$ which -T 2>/dev/null # redirect the same to stderr
$ # ✓
```
Expected behaviour, as illustrated by GNU `which`:
```sh
$ /usr/bin/which --version | head -1
GNU which v2.21, Copyright (C) 1999 - 2015 Carlo Wood.
$ /usr/bin/which nxcmd 2>/dev/null
$ echo $?
1
```
Interim solution:
```sh
# ~/.zshrc
alias which='command which'
```
OS, architecture and zsh version:
```sh
$ uname -a
Linux nakamu 4.18.9 #1 SMP PREEMPT Wed Sep 19 21:19:17 UTC 2018 x86_64 GNU/Linux
$ echo $ZSH_VERSION
5.6.2
```
Cheers,
--
Klaus Alexander Seistrup
https://klaus.seistrup.dk/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author