From e5e626d8adbcd564fd9ece1097446a05075621af Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Thu, 7 Sep 2023 08:05:49 +0200 Subject: use the $MAX variable --- makepass.zsh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'makepass.zsh') diff --git a/makepass.zsh b/makepass.zsh index c513086..558585b 100755 --- a/makepass.zsh +++ b/makepass.zsh @@ -19,7 +19,7 @@ # -g = global # -r = readonly -typeset -gri MAX_LENGTH=255 # max length of passwords +typeset -gri MAX=255 # max length of passwords typeset -gri RANGE_MAX=42 # max length when using random length typeset -gri RANGE_MIN=8 # min length when using random length typeset -gri PASS_WORDS=8 # number of words in passphrases @@ -217,10 +217,10 @@ function main() { h) _makepass_help && return 0;; l) - [[ $OPTARG = <0-255> ]] || die "-l takes a number between 0 and 255" + [[ $OPTARG = <0-> && $OPTARG -le $MAX ]] || die "-l takes a number between 0 and $MAX" LENGTH=$OPTARG;; n) - [[ $OPTARG = <1-255> ]] || die "-n takes a number between 1 and 255" + [[ $OPTARG = <1-> && $OPTARG -le $MAX ]] || die "-n takes a number between 1 and $MAX" NUMBER=$OPTARG;; p) PRINTLEN=1;; @@ -242,8 +242,10 @@ function main() { [[ -n $1 ]] && LENGTH=$1 # Check $LENGTH and $NUMBER - [[ $LENGTH = <0-255> ]] || die "length must be a number between 0 and 255" - [[ $NUMBER = <1-255> ]] || die "number-argument must be between 1 and 255" + # Both are integers so no need to check if they are numbers + # If they were somehow assigned to, say "xx", they would be 0 + (( 0 <= LENGTH && LENGTH <= MAX )) || die "length must be a number between 0 and $MAX" + (( 1 <= NUMBER && NUMBER <= MAX )) || die "number-argument must be between 1 and $MAX" # -- cgit v1.2.3