12

huge confession bear...

i just learned what set -e does in bash

i've been using logical and (&&) this whole time

😂😂😂😂😂😂😂😂

i have become what i hate 🤡🤡🤡

Comments
  • 7
    Now use trap in addition to set -e
  • -1
    Wish i could learn bash. Then again i havent bumped into literally any need of actually needing to code a complex bash program for literally anything. It was always something very simple
  • 3
    Some tips

    set -o errexit
    might be more verbose, but definitely cleaner to read.

    set -o pipefail is a good idea, too.

    Best is usually to still check explicitly cmds return code, cause you don't end up with a script where all error handling is implicit.
  • 3
    now get ready for "set -x" and be amazed
  • 4
    Everyone was a noob once...
  • 6
    God damn it. I was reading through comments and thinking "wtf they're on about?!? How's ´sed -e´ related to bash...?"

    i need to wake up better
  • 3
    I just recently delve into bash script again.

    My senior told me to use specific error code :

    - case A : exit 10

    - case B : exit 20

    and so on.

    So I can't use globally set -e in this case
  • 3
    set -x is indeed very very helpful. Explains all the mysteries of bash.
  • 3
    @netikras

    Have some coffee.

    (Might be used for rescucitation)

    Brazilian beans fresh grinded.
  • 4
    @cho-uc

    Not true.

    set -o errexit just takes care of all "unchecked" conditions.

    if ! thisIsABadIdea; then
    exit 20
    fi

    Still works.
    (given that thisIsABadIdea is a function with a return code != 0 or a program with exit code != 0).

    Conditionals are exempt from errexit.

    Thus errexit is an implicit fallback, which is why I would recommend doing explicit checks and using errexit as a failsafe.
  • 1
    @NeatNerdPrime I am a noob every six months as I forget all the things.
  • 2
    @Demolishun but at least you know you are and are not an arrogant prick about it. The Socratic way has always proven to be the best path forward.

    Don't worry, every time it will be better and you will forget less often.
Add Comment