Hacker News new | ask | show | jobs
by EdSchouten 1462 days ago
Booleans in shell scripts are little more than zero (true) and non-zero (false) exit codes.
1 comments

Ok, right. But then it should still say either "booleans are just numbers" or "numbers can be interpreted as booleans, i.e. are truthy or falsy".
It's not that cut & dry, as bash is doing evaluations; 0 and 1 can both be "true" if simply used without an evaluation, but add logic and it starts to matter (grep returns 0 if hit, 1 if not).

    [[ 0 ]] && echo "hit 0"
    [[ 1 ]] && echo "hit 1"
    grep -q 127 /etc/hosts && echo "hit grep"
    grep -q 128 /etc/hosts || echo "miss grep"