3 ms·
> Note that it's not even a bug here; it's necessary for disambiguation. I would call it a bug when there's one valid way to read it, and [ fails to see it. I
by jolmg 6y ago
> Note that it's not even a bug here; it's necessary for disambiguation.
I would call it a bug when there's one valid way to read it, and [ fails to see it. I don't see the ambiguation. For example, zsh's [ doesn't have these errors:
$ a=1; b=1; c='!'; d='!'
$ [ "$a" = "$b" -a "$c" = "$d" ]; echo $?
0
$ [ '!' '(' "$c" = "$d" ')' ]; echo $?
1
Same result with FreeBSD's tcsh's [.
I think bash's [ is just lacking the ability to backtrack while parsing its arguments.
Curiously, GNU's [ fails to parse the arguments of the first, but not the second's:
$ command [ "$a" = "$b" -a "$c" = "$d" ]; echo $?
[: extra argument ‘!’
2
$ command [ '!' '(' "$c" = "$d" ')' ]; echo $?
1
It seems its argument parsing works differently when using parentheses:
$ command [ "$a" = "$b" -a '(' "$c" = "$d" ')' ]; echo $?
0
- dataflow 6y agoI was just being a little sloppy in what I wrote. I meant you can encounter ambiguities in the language when you start using -a/-o or (). I didn't mean those particular examples' parse trees are ambiguous.