aboutsummaryrefslogtreecommitdiff
path: root/bin/rnda
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-09 17:15:40 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-09 17:20:10 +1200
commit9fb350dc7c8cc5259ef24e0cb097031179fab1d6 (patch)
tree839dd0b8ee3f5323b1cd6aefa22b605b99437d62 /bin/rnda
parentMention nosls/sls flags in slsf(1) man page (diff)
downloaddotfiles-9fb350dc7c8cc5259ef24e0cb097031179fab1d6.tar.gz
dotfiles-9fb350dc7c8cc5259ef24e0cb097031179fab1d6.zip
Improve commenting/exit handling in binscripts
Diffstat (limited to 'bin/rnda')
-rwxr-xr-xbin/rnda14
1 files changed, 12 insertions, 2 deletions
diff --git a/bin/rnda b/bin/rnda
index 99042bf6..078e5008 100755
--- a/bin/rnda
+++ b/bin/rnda
@@ -1,10 +1,20 @@
#!/bin/sh
-# Choose a random argument using rndi(1).
+# Choose a random argument using rndi(1)
+
+# Check we have at least one argument
if [ "$#" -eq 0 ] ; then
printf >&2 'rnda: No args given\n'
- exit 1
+ exit 2
fi
+
+# Get a random seed from rnds(1); if it's empty, that's still workable
seed=$(rnds)
+
+# Get a random integet from 1 to the number of arguments
argi=$(rndi 1 "$#" "$seed") || exit
+
+# Shift until that argument is the first argument
shift "$((argi-1))"
+
+# Print it
printf '%s\n' "$1"