Hacker News new | ask | show | jobs
by pdkl95 3882 days 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 ))
1 comments

Ah, thats great learned a new bash trick
Shorthand 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