Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Bug: [ "(" = ")" ] is true
- X-seq: zsh-workers 37362
- From: Martijn Dekker <martijn@xxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Bug: [ "(" = ")" ] is true
- Date: Wed, 09 Dec 2015 16:34:34 +0100
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
There is a string comparison bug with `[' and `test'; the result is true
if the first string starts with '(' and the second string starts with ')'.
$ [ "(" = ")" ] && echo oops || echo ok
oops
$ [ ")" = "(" ] && echo oops || echo ok
ok
$ [ "((" = "))" ] && echo oops || echo ok
oops
$ [ "((" = ")x" ] && echo oops || echo ok
oops
$ [ "(x" = ")" ] && echo oops || echo ok
oops
$ [ "x(" = ")" ] && echo oops || echo ok
ok
$ [ "(" = "x)" ] && echo oops || echo ok
ok
This appears to be a long-standing bug. I confirmed it in:
zsh 4.3.6
zsh 5.1.1
zsh 5.2
I also found that the bug does *not* exist in zsh 4.1.1.
Also, `[[' does not have this problem.
Credit to /u/tilkau on reddit for discovering this bug:
https://www.reddit.com/r/bash/comments/3w1hm4/how_to_compare_values_to_literal/cxsknzh
Thanks,
- Martijn
Messages sorted by:
Reverse Date,
Date,
Thread,
Author