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/"}
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 \