aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-07-15 21:06:11 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-07-15 21:06:11 +1200
commita7ca17b7dc5884bf5ecc9e61923afeb6e972bffd (patch)
treed0ef4554efdd4de274d520c6384c3aacffc16c98 /bin
parentClean up and document syl(6) (diff)
downloaddotfiles-a7ca17b7dc5884bf5ecc9e61923afeb6e972bffd.tar.gz
dotfiles-a7ca17b7dc5884bf5ecc9e61923afeb6e972bffd.zip
Replace use of ${var:?} with explicit errors
<http://mywiki.wooledge.org/BashFAQ/100#Default_or_alternate_values> >Nobody ever uses ${var?word} or ${var:?word}. Please pretend they don't >exist, just like you pretend set -e and set -u don't exist. ><tejr> from FAQ 100: >Nobody ever uses ${var?word} or ${var:?word}. ><tejr> why is that? just because it's unwieldy, or are there other >technical reasons? ><ormaaj> tejr: Putting random fatal unhandlable errors into a script is >generally useless. ><tejr> ormaaj: is it less handleable than a more explicit check, like >`[[ $var ]] || exit 1` ? ><ormaaj> yes ><ormaaj> # : ; ${_[RANDOM%2]?:you win} ><shbot> ormaaj: no output ><ormaaj> didn't win ><tejr> i was thinking more as a terse means of perhaps asserting a >variable had a value, like a positional parameter; are you saying if >you really did just want to write to stderr and exit with failure, it's >still inappropriate? ><ormaaj> depends on the complexity I suppose but I'd not consider that >unless it's the global scope in a file you know isn't going to be >sourced and has no other explicit error handling. Even then it's ugly >because it bails out in the middle of evaluating parameters that >technically could have side-effects and such. ><tejr> ahh yes, kinda a separation of concerns ><tejr> that makes more sense now! thank you > * tejr combs his scripts to see if he's used it anywhere ><ormaaj> tejr: another reason is the type of error is a bash error >which usually indicates a problem with the script where bash itself >can't continue. An unset var isn't a " bash error", You can even make >it print counterintuitive error messages that look like bash internal >errors. ><tejr> ormaaj: also compelling ><tejr> i've found a few "{@:?}"s in here so i'm fixing them up now ><tejr> thanks for the analysis
Diffstat (limited to 'bin')
-rwxr-xr-xbin/jfcd4
-rwxr-xr-xbin/rfcf9
-rwxr-xr-xbin/rfcr9
3 files changed, 18 insertions, 4 deletions
diff --git a/bin/jfcd b/bin/jfcd
index 63fd185c..87b669fd 100755
--- a/bin/jfcd
+++ b/bin/jfcd
@@ -18,8 +18,8 @@ inw() {
logger --tag "$self"
}
-# Drectory to check is first and only argument; move into it
-cd -- "${1:?}" || exit
+# Directory to check is first and only argument; defaults to current directory
+cd -- "${1:-.}" || exit
# Run a while loop over inotifywait(1) calls, running jfc(1) on the working
# directory
diff --git a/bin/rfcf b/bin/rfcf
index 48cc2d43..72c076a9 100755
--- a/bin/rfcf
+++ b/bin/rfcf
@@ -1,5 +1,12 @@
#!/bin/sh
+# Figure out RFC number
+self=rfcf
+if ! [ "$1" ] ; then
+ printf >&2 '%s: Need an RFC number\n' "$self"
+ exit 2
+fi
+rn=$1
+
# Retrieve the RFC with curl(1)
-rn=${1?Need an RFC number}
curl https://tools.ietf.org/rfc/rfc"$rn".txt
diff --git a/bin/rfcr b/bin/rfcr
index a11457a9..74488c8c 100755
--- a/bin/rfcr
+++ b/bin/rfcr
@@ -1,7 +1,14 @@
#!/bin/sh
+# Figure out RFC number
+self=rfcr
+if ! [ "$1" ] ; then
+ printf >&2 '%s: Need an RFC number\n' "$self"
+ exit 2
+fi
+rn=$1
+
# Retrieve the RFC with rfcf(1)
-rn=${1?Need an RFC number}
rfcf "$rn" |
# Pipe it through rfct(1) to format it as text