X-Git-Url: https://git.armaanb.net/?a=blobdiff_plain;f=fortune;h=cbf19848130a0f74ad677e2fc98f0ae98cf901b1;hb=f840ce3d2989c8e22bcb2ea47b0ed31ab26564e1;hp=a8589a5f9e6a5ba8c4af5d12501becaf16c7270e;hpb=48374cb189a58ab6a44871c7c744a1f67f986089;p=bin.git diff --git a/fortune b/fortune index a8589a5..cbf1984 100755 --- a/fortune +++ b/fortune @@ -16,8 +16,14 @@ a simple POSIX sh/awk implementation of fortune Exit codes: 0 success - 1 argument error - 2 parse error' + 1 generic error + 2 argument parsing error' +} + +parse_err() { + echo "$1" + $2 + exit 2 } DIR=${FORTUNEDIR:-"/usr/share/fortune/"} @@ -45,22 +51,22 @@ while [ "$1" != "" ]; do exit ;; *) - echo "ERROR: unknown option \"$1\"" - usage - exit 1 + parse_err "ERROR: unknown option \"$1\"" usage ;; esac shift 2 done [ "$MAXLENGTH" -lt "$MINLENGTH" ] && { - echo "ERROR: maximum length is less than minimum length" - exit 2 + parse_err "ERROR: maximum length is less than minimum length" } [ -d "$FILE" ] && { - echo "ERROR: directory given, please provide a file or glob of files" - exit 2 + parse_err "ERROR: directory given, please provide a file or glob of files" +} + +[ "$(find $FILE -maxdepth 1 -print -quit 2> /dev/null)" ] || { + parse_err "ERROR: no such file or directory" } awk -v maxlen=$MAXLENGTH -v minlen=$MINLENGTH \