3 ms·
> invoking another shell That wasn't a subshell - $(( )) is Arithmetic Expansion. (you may be thinking of $( ) for Command Substitution) $ echo $BASH_SUBS
by pdkl95 11y ago
> invoking another shell
That wasn't a subshell - $(( )) is Arithmetic Expansion. (you may be thinking of $( ) for Command Substitution)
$ echo $BASH_SUBSHELL $((BASH_SUBSHELL)) $(echo $BASH_SUBSHELL)
0 0 1
Now, using the result of a boolean is a bit strange; I would have used your math with the modern expansion style:
# the new style allows spaces
STATE=$(( 1 - $STATE ))
- icefox 11y agoAh, thats great learned a new bash trick
- barrkel 11y agoShorthand for $(( )) is $[ ] In predicate contexts (which means return code in bash) like if, while or the left hand side of '&&', consider using (( )) - this has an exit code of 0 if the arithmetic expression is true (non-zero) and 1 otherwise. Use it like this: let x=3*3 if (( x > 5 )); then echo greater than five else echo less than or equal to five end