Note to all, prepend all your bash script with
"set -o errexit -o nounset -o pipefail"
It'll save you headaches.
"set -o errexit -o nounset -o pipefail"
It'll save you headaches.
The last option is unfortunately harder to use, since some programs misbehave in pipelines.
set -o nounset (set -u): exit script when it tries to use undeclared variables
set -o pipefail: returns error from pipe `|` if any of the commands in the pipe fail (normally just returns an error if the last fails)
To get the same effect as the "set -o errexit -o nounset", I think you can use "#!/bin/bash -e -u". (There seems to be no option for pipefail.)
bash '-e -u' $file
But you can do #!/bin/bash -eu #!/bin/bash
set -eu
IFS=$'\n\t'
(Wish there was a shorthand version of pipefail, then I'd always use that too.)