Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] Use == in expressions instead of the deprecated =



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