So, we all know that when writing a shell script, you start:
#! /bin/sh
#
# description/author/copyright/blah-blah-blah
set -e
....
What I didn't ever see mentioned is that if you're assuming set -e, command substitution — `cmd` or $(cmd) — with a non-zero exit status will not cause the script to abort.
There's a simple solution, fortunately:
tmp=`cmd`
do_stuff_with $tmp
Whilst I'm onto it, if you're reading a stream of words into the positional ($1 etc) values with set --, you really should check the number of parameters. Either:
tmp=`date +"%Y %m %d"`
set -- $tmp
[ $# = 3 ]
or
tmp=`date +"%Y %m %d"`
set -- $tmp
year=$1; month=$2; day=${3:?date went wrong}
