Remix.run Logo
amiga386 3 hours ago

Well that's exciting. I learned a lot of uses for ":" today.

However, the only one I already knew...

    if some-command; then
        :                            # command required
    else
        echo "command failed"
    fi
I used to do that until I learned of

    if ! some-command; then
        echo "command failed"
    fi
It's in the POSIX standard so it's not just a bashism: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V...

> If the pipeline does not begin with the "!" reserved word, the exit status shall be the exit status of the last command specified in the pipeline. Otherwise, the exit status shall be the logical NOT of the exit status of the last command

mcc1ane 2 hours ago | parent [-]

https://github.com/anordal/shellharden/blob/master/how_to_do...

mananaysiempre an hour ago | parent [-]

TL;DR: The old-school empty branch preserves $?, while logical negation doesn’t. Sure I guess, but this is not always relevant.