Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

... or perhaps, as the article suggests, that parsing was hard when we first started doing it decades ago and not everyone got it right.

If it wasn't abundantly clear, this is not an issue with any of the shells today.



It's amusing that parsing theory was already at least 1-2 decades old by the time they made this mistake (consider that ALGOL 60 had a complicated grammar, introducing BNF too). I'd chalk it up to this being a shell language that was evolved rather than designed.


I wouldn’t say that parsing is hard (precedence parsing is especially not hard), but instead that logical operators and grouping inside test aka [ were both a bad idea (given a sufficiently complex expression, I expect you can still confuse a human as to what’s an operator and what’s a string even if POSIX is precise enough to dictate a single interpretation) and unnecessary (the shell itself has perfectly serviceable !, &&, ||, and grouping, though the ! is a bit awkward and seems to be a later addition).

If you omit those, a fairly intuitive unambiguous parse is very easy: if we’re [, check last argument is ] and throw it away; if one argument, return whether it’s empty; otherwise, if two, the first is a unary operator, evaluate and return that; otherwise, if three, the second is a binary operator, evaluate and return that; otherwise fail. That’s it.


> If it wasn't abundantly clear, this is not an issue with any of the shells today.

The least-common-denominator aka /bin/sh and its syntax will stick around for decades to come. You can't rely on any of the "modern" shells to be around, particularly if you write scripts that target a multitude of unix-like systems (macOS, xBSD, Linux).


The OP gives two examples where it is not fixed, because bash is so poorly designed that the fixes are partial hacks.


> If it wasn't abundantly clear, this is not an issue with any of the shells today.

I really doubt it. If the comparison parameters are undistinguishable from the operators, it's only a matter of enough creativity and people will to find new ways to break it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: