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=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 c673db4a for ; Sun, 12 Jan 2020 13:59:55 +0000 (UTC) Received: (qmail 7525 invoked by alias); 12 Jan 2020 13:59:47 -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: 24651 Received: (qmail 12639 invoked by uid 1010); 12 Jan 2020 13:59:47 -0000 X-Qmail-Scanner-Diagnostics: from out5-smtp.messagingengine.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(66.111.4.29):SA:0(-2.6/5.0):. Processed in 4.698775 secs); 12 Jan 2020 13:59:47 -0000 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdeikedgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfffgr nhhivghlucfuhhgrhhgrfhdfuceougdrshesuggrnhhivghlrdhshhgrhhgrfhdrnhgrmh gvqeenucfrrghrrghmpehmrghilhhfrhhomhepugdrshesuggrnhhivghlrdhshhgrhhgr fhdrnhgrmhgvnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.7-740-g7d9d84e-fmstable-20200109v1 Mime-Version: 1.0 Message-Id: <69a81ce1-245b-478c-bd43-08a5ad7aa7fa@www.fastmail.com> In-Reply-To: <20200112120353.snhivqosevvv526a@chaz.gmail.com> References: <20200112100906.GA95942__47727.4053309642$1578823915$gmane$org@pooh.prefix.duckdns.org> <20200112120353.snhivqosevvv526a@chaz.gmail.com> Date: Sun, 12 Jan 2020 13:58:43 +0000 From: "Daniel Shahaf" To: zsh-users@zsh.org Cc: "Frank Gallacher" Subject: Re: Use of == in functions Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Stephane Chazelas wrote on Sun, 12 Jan 2020 12:03 +00:00: > [repost to zsh-users. I'll see if I can add a mutt hook to avoid > the problem in the future]. >=20 > 2020-01-12 11:09:06 +0100, Kusalananda K=C3=A4h=C3=A4ri: > [...] > > =3D=3D within [[ ]] > > =3D within [ ] > >=20 > > ... just like in bash (but bash allows its built in test/[ utility t= o > > understand =3D=3D too) > [...] >=20 > zsh's [ builtin also supports =3D=3D as an alias of =3D (like its [[ > ]] construct also supports =3D=3D as an alias of =3D), but in zsh, > =3Dcmd is an operator that expands to the path of the cmd command, >=20 > $ echo =3Dls > /usr/bin/ls >=20 > so you would need: >=20 > [ a '=3D=3D' b ] >=20 > (or disable the =3Dcmd feature with set +o equals) if for some > reason you wanted to use the non-standard =3D=3D in place of =3D. >=20 > Just like you need >=20 > [ a '=3D~' regex ] >=20 > for regex matching. >=20 > And >=20 > [ a '<' b ] >=20 > to compare strings lexically as < is also a redirection > operator. >=20 > Now, as none of <, =3D=3D, =3D~ 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: >=20 > [[ a =3D~ b ]], [[ a < b ]], [[ a =3D=3D b ]] are all fine (but then > again, there's no need to double the =3D. =3D=3D 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) The reason for the difference between =C2=AB[ x =3D=3D y ]=C2=BB and =C2= =AB[[ x =3D=3D y ]]=C2=BB is that [ is a _builtin_, so it's parsed using the same rules as any random= external command, whereas [[ is a _reserved word_, part of the syntax, like '&&', so the normal command line syntax rules don't apply within it. This is also why =C2=AB[[ -n foo && -n bar ]]=C2=BB works