Hacker News new | ask | show | jobs
by ajkjk 3094 days ago
I hate Bash and all of its relatives. No language where equality is tested with -eq should be in use in 2017; we can do so much better.
2 comments

Totally agree, it is just unintuitive for anyone who just knows any type of a "normal" language
I actually kind of like it, powershell also has -eq, and there's no chance of mixing up assignment and equality operators.
You mix up the := operator with the = operator? (-:

There's no chance of mixing them up with the "test" command, note, which is what ajkjk was talking about (even though xe erroneously attributed this to the Bourne Again shell language), because the test command has no assignment operator. Whereas what it does have is a whole bunch of syntactic gotchas that bite people with depressing regularity.

* Miss quoting variables, and suddenly your unary operator turns into an expression that always evaluates true, because with 1 argument test merely tests whether the argument is non-blank, which a unary operator is of course.

* = is string comparison, and -eq is numeric comparison. Yes, you want the other one.

* ... but == is a non-standard bashism that does not work in scripts interpreted by /bin/sh (which is usually something like the Korn or Almquist shell) on many modern systems.

* ... and if you are using the Z, Korn, or Bourne Again shells, don't forget that you need to quote the < and > operators.

* Beware the variable whose value has a minus sign as its first character. All comparisons for safety need to be of the form x"$var" = x"something" .

"Real" languages use "=" and "==" ;)

Was unfamiliar with the minefield of bash issues, still, I do like the -eq operator, even if bash implements it poorly.

On the contrary, a real language uses .EQ. . == is for the chattering classes who use the # sign when posting to social media. You appear to be eating quiche. (-:

* http://gordonbell.azurewebsites.net/ibm-026/ibm-026-ref-27.j...

Rex Conn knows how a real language does relational operators.

* https://jpsoft.com/help/conditionalexpressions.htm#r