Hacker News new | ask | show | jobs
by icefox 3883 days ago
Ah, thats great learned a new bash trick
1 comments

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