From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-workers-return-43523-ml=inbox.vuxu.org@zsh.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id b536843e for ; Mon, 24 Sep 2018 08:00:58 +0000 (UTC) Received: (qmail 18040 invoked by alias); 24 Sep 2018 08:00:43 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 43523 Received: (qmail 9736 invoked by uid 1010); 24 Sep 2018 08:00:42 -0000 X-Qmail-Scanner-Diagnostics: from mail-lf1-f41.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.167.41):SA:0(-1.9/5.0):. Processed in 3.902754 secs); 24 Sep 2018 08:00:42 -0000 X-Envelope-From: klaus@seistrup.dk X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state: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=NEewy59L714o7IxGfiL/lNADZardejizqPbD9rLmQ+63Ph22eX75kmR5388hWuPen3 IkmS13PYSioZkbIo580JEcZFXanTaf8MvWGnzgc0fBQ8iZtPT6QlmwCBEEUNu98I5Qf8 UPadorugzoeobe15uy0mPCtq8jOADOMoJITZltw2dEBJiZtdzfA/AcmXDPQEuEhumo2t jA/0r25pHSA1W6xDZZwIBGnWbSHNEU+/BtLimZe+4tE8sLuO4zV6zQ4NiI2lqUfOaO1m WY553fLt+PfBUFGaizF/9KeyqXxZtt7RHVbH+vzKk7ovbKFRchVUPrXOvzqvXZQuq9n3 ux/Q== X-Gm-Message-State: APzg51AOasliekjdzaT6wx3uyH7bNk6eX23WbCJ3UhlfI6GCBKerWHf3 VmrVosGDg5Rtj/Qh1r4baIUYAeVrYcdhoA== X-Google-Smtp-Source: ANB0VdZ3Re2YboSizPLbL/1XdZL5jfi7ALg9/KS5kfL6xFRGX9R0AmGbeuPioPMDGT9pCylTyIm7uQ== X-Received: by 2002:a19:cb09:: with SMTP id b9-v6mr5097717lfg.117.1537776033593; Mon, 24 Sep 2018 01:00:33 -0700 (PDT) Date: Mon, 24 Sep 2018 10:00:31 +0200 From: Klaus Alexander Seistrup To: Zsh Workers Subject: BUG: Shell builtin `which` prints non-existent commands to stdout Message-ID: <20180924080031.ee7lqmthxpmvqaal@klaus.seistrup.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit Organization: Bornmesh, Bornholm, Denmark X-XRI: xri://@id*kas Scuttlebutt: @dBQlwh9Gtr3i5YMOGtIOKtGNVepeu+nyb6KGl1vtOcM=.ed25519 OpenAlias: klaus.seistrup.dk VCard: uuid=d4790855-a33a-5757-8154-8ecce7a04f9d; uri=https://klaus.seistrup.dk/vcard.vcf OpenPGP: id=D2620A739DBE0D41216ADF2705483F10A54192F8; uri=https://klaus.seistrup.dk/pubkey.asc; preference=sign User-Agent: NeoMutt/20180716 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/