Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] Use == in expressions instead of the deprecated =
- X-seq: zsh-workers 39270
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: Peter Stephenson <p.stephenson@xxxxxxxxxxx>, zsh-workers@xxxxxxx
- Subject: Re: [PATCH] Use == in expressions instead of the deprecated =
- Date: Thu, 8 Sep 2016 16:06:32 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=FvoaDiQbpGkJvfebGmJDWE+rEXlqPSOXDoHNmE1/cRE=; b=tfGzNAY2vwhSyC8G+bStA5q+ZnBFWBafcYFkf0DaIzXkwlaqizZaVZF35UG6EpwsPB pHpT7QkeBaI64HoABCtqsBymJHyBPlm1C4LNLVO3IINgKbyrqAfuDNFXbrMbIHQ/LF5U B6j1qzJIF0i1L52x7q1SkPL2lQJ7VW2UaehcrN+zDq23iKlYqQka3EjY5dCA/q5j+EsS ElDxbnCQ9iXFwNdKQCHyFLF9OWuwGf/bJraD+R7PZ+qYYZAUQ5q5iWARr2LB77VLrdh/ h+Z+Np+LBU9tT6ZReWjgh5JjCOiKQjjltmdXh/Le/A5bkhRpArbPGhIpijcQ8RoHM3oh FB6w==
- In-reply-to: <20160908143128.GA14933@chaz.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mail-followup-to: Peter Stephenson <p.stephenson@xxxxxxxxxxx>, zsh-workers@xxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20160905212754.24998-1-tgyurci@gmail.com> <20160908093516.4fc2dd1e@pwslap01u.europe.root.pri> <20160908121628.78977edd@pwslap01u.europe.root.pri> <20160908143128.GA14933@chaz.gmail.com>
2016-09-08 15:31:28 +0100, Stephane Chazelas:
[...]
> ksh93 also makes "==" obsolete in [[...]]. "==" is still not
> POSIX (and likely not going to be soon as requests to add it
> have been rejected (IIRC)) for the "test"/"[" utility (or expr).
[...]
Appart from bash 2.02, I don't know of a shell implementation
that treats [[ = ]] differently from [[ == ]] (or [ = ] vs [ ==
] for those "[" implementations that support ==) however note
that yash has a 3rd operator: [ === ] that is short for [ '<=' ]
&& [ '>=' ] or [ ! '<' ] && [ ! '>' ].
As in yash like in bash or ksh93 (but not zsh), < and > for
string comparison use strcoll() (like sort/expr or awk's </> for
strings) while == uses strcmp. And in some locales, there are
strings that sort the same even though they are different.
yash's === is a test to check that two strings sort the same,
like the "=" operator of expr (or the == operator of some awk
implementations as currently required by POSIX (though that's
going to change)).
For instance in a en_GB.UTF-8 locale on a GNU system, \u2461
sorts the same as \u2462 (in that case, a bug).
expr $'\u2461' = $'\u2462'
and
yash -c '[ \u2461 === \u2462 ]'
return true while
[[ \u2461 < \u2462 ]] and [[ \u2461 > \u2462 ]]
both return false in bash and ksh93.
zsh's behaviour is more consistent here but means that for
instance
[[ Stéphane < Stuff ]]
returns false (while bash and ksh93 return true) even though
I'd exect é to sort before u.
See also
https://unix.stackexchange.com/questions/56655/what-is-the-difference-between-a-z-and-a-z/56674#56674
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author