From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,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 3a4c9311 for ; Sun, 12 Jan 2020 12:04:37 +0000 (UTC) Received: (qmail 12516 invoked by alias); 12 Jan 2020 12:04:29 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 24650 Received: (qmail 13184 invoked by uid 1010); 12 Jan 2020 12:04:29 -0000 X-Qmail-Scanner-Diagnostics: from mail-wm1-f48.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.1/25684. spamassassin: 3.4.2. Clear:RC:0(209.85.128.48):SA:0(-2.0/5.0):. Processed in 0.770696 secs); 12 Jan 2020 12:04:29 -0000 X-Envelope-From: stephane.chazelas@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.128.48 as permitted sender) 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:newsgroups:subject:message-id :mail-followup-to:references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:archived-at:user-agent; bh=yHDWPV6QJea9+M6mAv4mp/FijXQnHha8vV77wEPdiP8=; b=I/grkYOyJHm4783wjX2kkh5mOkmZuKANuVJxK9TfQOGanXhREsDtM0uo7JCh5IKkUk WktX9OzSUbdHW3ChoWL+qNKlXb4vIIhicNSdvy4cKpoqKC/HbkfIrpSXcvo4YAqZd8XF 2Rfl7rxEi86A2syX1F1GmZ7kQo9aphKeaNUuEAnH01BcUIxvv8ruVaA9Wx/Vnqnruko/ 5hFF71H5/iv/g6P1INwAH41j44plT5fryWfMuHt9VuWAdtEpqaEIt8Jvdr5ZTyZ5xIcC G/PZ1M/ddgM1DShL8+eXrAv4eJV3NX5aw12gDM7y7wjy6RDrnpsfQX4nS5tclHYMEGkx drvw== X-Gm-Message-State: APjAAAX1zUYQBhEJYrVxTqX1pJuIoXEZHsboWMSmiH7ibkd/dJo8C5cH FqJfvBr7Tkff2KlRGHFSUnFYbnbd X-Google-Smtp-Source: APXvYqzhgjqGummKRBSsv8pMfoQMeRSwgAsrcwcNdKRgDP74H+WBSlgOs5OXkoyh0eMv3hDscf8m3Q== X-Received: by 2002:a1c:1bc3:: with SMTP id b186mr14710751wmb.79.1578830635200; Sun, 12 Jan 2020 04:03:55 -0800 (PST) Date: Sun, 12 Jan 2020 12:03:53 +0000 From: Stephane Chazelas To: zsh-users@zsh.org Newsgroups: gmane.comp.shells.zsh.devel Subject: Re: Use of == in functions Message-ID: <20200112120353.snhivqosevvv526a@chaz.gmail.com> Mail-Followup-To: zsh-users@zsh.org References: <20200112100906.GA95942__47727.4053309642$1578823915$gmane$org@pooh.prefix.duckdns.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200112100906.GA95942__47727.4053309642$1578823915$gmane$org@pooh.prefix.duckdns.org> X-Seq: 45286 Archived-At: User-Agent: NeoMutt/20180716 [repost to zsh-users. I'll see if I can add a mutt hook to avoid the problem in the future]. 2020-01-12 11:09:06 +0100, Kusalananda Kähäri: [...] > == within [[ ]] > = within [ ] > > ... just like in bash (but bash allows its built in test/[ utility to > understand == too) [...] zsh's [ builtin also supports == as an alias of = (like its [[ ]] construct also supports == as an alias of =), but in zsh, =cmd is an operator that expands to the path of the cmd command, $ echo =ls /usr/bin/ls so you would need: [ a '==' b ] (or disable the =cmd feature with set +o equals) if for some reason you wanted to use the non-standard == in place of =. Just like you need [ a '=~' regex ] for regex matching. And [ a '<' b ] to compare strings lexically as < is also a redirection operator. Now, as none of <, ==, =~ are standard [ operators (so sh compatibility is no longer a good reason to use the "[" command), you might as well use the ksh-style [[...]] construct which doesn't have this kind of issue: [[ a =~ b ]], [[ a < b ]], [[ a == b ]] are all fine (but then again, there's no need to double the =. == is an operator that is needed in languages where there's a need to disambiguate between assignment and equality comparison, but inside [[...]] (as opposed to ((...)) for instance), there's no assignment) -- Stephane