2015-11-07 19:00 -0500
set -eux is a super useful bash trick I’ve been using in Chef and
Rex tasks. I’m going to break it down and
explain it one option at a time:
cmd1 && cmd2 && cmd3
is equivalent to this
set -e cmd1 cmd2 cmd3
The shell prints a message to stderr when it tries to expand a variable that is not set. Also it immediately exits. An interactive shell will not exit. I think this is similar to Perl’s use strictures which is something Moo enables.
The shell prints each command in a script to stderr before running it. I think this would be particularly useful in Rex. And Chef.
set -x echo hey echo woah
+ echo hey hey + echo woah woah
set -o pipefail
Pipelines fail on the first command which fails instead of dying later on down the pipeline. This is especially good when cmd3 is a command that always succeeds (like echo):
cmd1 | cmd2 | cmd3