Hacker News new | past | comments | ask | show | jobs | submit login

The square brackets for arithmetic conditionals in bash are deprecated. Rather than:

    [ $[$RANDOM % 10] = 0 ]
...you can use double-parentheses. Therein, you can omit the `$` on variables and, remember, the expression evaluates to true for any non-zero value. Thus, instead:

    (( RANDOM % 10 ))



$[...] also establishes an arithmetic context, so

  $[RANDOM % 10]
works fine – but you're right, $[...] is not even mentioned in the manual any longer. The release notes[1] say that it's "no longer supported" in the changes for Bash 2.0 (that's 1996!), and Chet Ramey talks about it in the bug-bash mailing list[2].

[1]: http://tiswww.case.edu/php/chet/bash/NEWS

[2]: https://lists.gnu.org/archive/html/bug-bash/2012-04/msg00034...


You changed the probability here from 10% to 90% by inverting the test.


True, you can just invert: alias clear='if ! (( RANDOM % 10 )); then timeout 3 cmatrix; clear; else clear; fi'


((RANDOM % 10)) || timeout 3 cmatrix ; clear


This perfectly illustrates why I never bothered to learn bash syntax, and always just google for examples.




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

Search: