From 40205de8e651877fe6c5c85dbde154c6156d8b15 Mon Sep 17 00:00:00 2001 From: Johannes <76924386+Jojodicus@users.noreply.github.com> Date: Fri, 6 May 2022 23:45:36 +0200 Subject: [PATCH] handle invalid input (fix #22) read_choice() only handles wrong input numbers correct it **should** set the default value of 1 if nothing was entered it should also print an error if a wrong number (or no number at all) was typed this commit also fixes #22, as this error was also caused by handling input wrong --- install.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index 647eb89..8060096 100755 --- a/install.sh +++ b/install.sh @@ -22,15 +22,19 @@ check_impulse_response_directory() { } read_choice() { - CHOICE="" - while [[ ! $CHOICE =~ ^[1-5]+$ ]]; do + while :; do read -r CHOICE - if [ "$CHOICE" -lt 1 ] || [ "$CHOICE" -gt 5 ]; then - echo "Invalid option! Please input a value between 1 and 5!" + if [ -z "$CHOICE" ]; then + CHOICE=1 #default fi + if [[ $CHOICE =~ ^[1-5]+$ ]]; then + break + fi + echo "Invalid option! Please input a value between 1 and 5!" done } + install_menu(){ echo "Please select an option for presets installation (Default=1)" echo "1) Install all presets"