chore(unitproc/bkt-processArgs):Update with die()
[BK-2020-03.git] / unitproc / bkt-yellDieMust
1 #!/bin/bash
2 # Desc: Defines bash functions yell(), die(), and must(), which are useful for
3 # indicating where in a script an error occurs.
4 # Note: All three functions should be added together if used at all.
5 # Ref/Attrib: [1] Yell, Die, Try Three-Fingered Claw technique https://stackoverflow.com/a/25515370
6 # Depends: GNU Coreutils 8.30
7 # Version 1.0.0
8
9 #==BEGIN Define script parameters==
10 #==END Define script parameters==
11
12 #===BEGIN Declare local script functions===
13 yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
14 die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status
15 must() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails
16 #===END Declare local script functions===
17
18 #==BEGIN sample code==
19 yell "This message should appear in stderr.";
20 must echo "This message should appear in stdout.";
21 must eeeecho "This message should appear in an error message in stderr.";
22 yell "This message should not appear because \"must eeeecho\" failed.";
23 #==END sample code==