コマンドを実行して、失敗した場合はそのリターン コードを表示しようとしています。
if ! /bin/false
then
tee >(mail -s "failed" $USER) <<EOF
Failed with code $?
EOF
fi
上記は常に「0」をエコーしますが、「1」が表示されることを期待しています。
以下は機能しますが、それほど単純ではなく、 とうまく連携しませんset -o errexit
。
/bin/false
ret=$?
if [ $ret -ne 0 ]
then
tee >(mail -s "failed" $USER) <<EOF
Failed with code $ret
EOF
fi