Commit | Line | Data |
---|---|---|
0ed005b0 SBS |
1 | #!/bin/bash |
2 | # Desc: Defines bash functions yell(), die(), and try(), which are useful for | |
3 | # indicating where in a script an error occurs. | |
4 | # Ref/Attrib: [1] Yell, Die, Try Three-Fingered Claw technique https://stackoverflow.com/a/25515370 | |
5 | # Depends: GNU Coreutils 8.30 | |
6 | ||
7 | #==BEGIN Define script parameters== | |
8 | #==END Define script parameters== | |
9 | ||
10 | #===BEGIN Declare local script functions=== | |
11 | yell() { echo "$0: $*" >&2; } | |
12 | die() { yell "$*"; exit 111; } | |
13 | try() { "$@" || die "cannot $*"; } | |
14 | #===END Declare local script functions=== | |
15 | ||
16 | #==BEGIN sample code== | |
17 | yell "This message should appear in stderr."; | |
18 | try echo "This message should appear in stdout."; | |
19 | try eeeecho "This message should appear in an error message in stderr."; | |
20 | yell "This message should not appear because \"try eeeecho\" failed."; | |
21 | #==END sample code== |