input validation

This commit is contained in:
Heavybullets8 2022-07-26 16:45:52 -06:00
parent c44e09e300
commit dd14c6665c
2 changed files with 5 additions and 6 deletions

View File

@ -30,9 +30,8 @@ menu(){
;;
4)
read -rt 600 -p "Please type the max number of backups to keep: " number_of_backups
re='^[0-9]+$'
number_of_backups=$number_of_backups
! [[ $number_of_backups =~ $re ]] && echo -e "Error: -b needs to be assigned an interger\n\"""$number_of_backups""\" is not an interger" >&2 && exit
! [[ $number_of_backups =~ ^[0-9]+$ ]] && echo -e "Error: -b needs to be assigned an interger\n\"""$number_of_backups""\" is not an interger" >&2 && exit
[[ "$number_of_backups" -le 0 ]] && echo "Error: Number of backups is required to be at least 1" && exit
echo "Generating backup, please be patient for output.."
backup "$number_of_backups"
@ -107,6 +106,7 @@ menu(){
elif [[ $current_selection == 1 ]]; then
echo "Up to how many backups should we keep?"
read -rt 600 -p "Please type an integer: " up_backups
! [[ $up_backups =~ ^[0-9]+$ ]] && echo -e "Error: \"$up_backups\" is invalid, it needs to be an integer\nNOT adding it to the list" && sleep 5 && continue
update_selection+=("-b" "$up_backups")
elif [[ $current_selection == 2 ]]; then
read -rt 600 -p "What is the name of the application we should ignore?: " up_ignore
@ -120,6 +120,7 @@ menu(){
elif [[ $current_selection == 6 ]]; then
echo "What do you want your timeout to be?"
read -rt 600 -p "Please type an integer: " up_timeout
! [[ $up_timeout =~ ^[0-9]+$ ]] && echo -e "Error: \"$up_timeout\" is invalid, it needs to be an integer\nNOT adding it to the list" && sleep 5 && continue
update_selection+=("-t" "$up_timeout")
elif [[ $current_selection == 7 ]]; then
update_selection+=("-s")

View File

@ -56,9 +56,8 @@ do
exit
;;
b)
re='^[0-9]+$'
number_of_backups=$OPTARG
! [[ $OPTARG =~ $re ]] && echo -e "Error: -b needs to be assigned an interger\n\"""$number_of_backups""\" is not an interger" >&2 && exit
! [[ $OPTARG =~ ^[0-9]+$ ]] && echo -e "Error: -b needs to be assigned an interger\n\"""$number_of_backups""\" is not an interger" >&2 && exit
[[ "$number_of_backups" -le 0 ]] && echo "Error: Number of backups is required to be at least 1" && exit
;;
r)
@ -77,9 +76,8 @@ do
fi
;;
t)
re='^[0-9]+$'
timeout=$OPTARG
! [[ $timeout =~ $re ]] && echo -e "Error: -t needs to be assigned an interger\n\"""$timeout""\" is not an interger" >&2 && exit
! [[ $timeout =~ ^[0-9]+$ ]] && echo -e "Error: -t needs to be assigned an interger\n\"""$timeout""\" is not an interger" >&2 && exit
;;
s)
sync="true"