Skip to content

Comment on Writing Robust Bash Shell Scripts

Comments

These are generally good tips. I swear by

    set -e # same as set -o errexit
and I like using list constructs (&& ||) in lieu of simple `if` test blocks but it's really important to remember that list constructs aren't exactly the same. This always catches me out:
    if [ -e "missingfile" ]
    then
        echo "you'll never see this"
    fi
(above runs fine with set -e)
    [ -e "missingfile" ] && echo "you'll never see this"
(while that one correctly fails and thus `set -e` fails the script)

I generally stick an `|| true` on the end of those list constructs.

fwiw.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.