4 ms·
The square brackets for arithmetic conditionals in bash are deprecated. Rather than: [ $[$RANDOM % 10] = 0 ] ...you can use double-parentheses. Therein, y
by Xophmeister 7y ago
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 ))
- kd5bjo 7y agoYou changed the probability here from 10% to 90% by inverting the test.
- bewuethr 7y ago$[...] 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 http://tiswww.case.edu/php/chet/bash/NEWS [2]: https://lists.gnu.org/archive/html/bug-bash/2012-04/msg00034.html https://lists.gnu.org/archive/html/bug-bash/2012-04/msg00034...
- artursapek 7y agoThis perfectly illustrates why I never bothered to learn bash syntax, and always just google for examples.