From 468ad4017fab18b3e72ec89054359a2290bfef5c Mon Sep 17 00:00:00 2001 From: deicidus Date: Fri, 26 May 2023 02:13:55 -0700 Subject: [PATCH] fixed ask_yn again --- spells/cantrips/ask_yn | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/spells/cantrips/ask_yn b/spells/cantrips/ask_yn index 65ebb84..a84da0b 100755 --- a/spells/cantrips/ask_yn +++ b/spells/cantrips/ask_yn @@ -5,17 +5,18 @@ ask_yn() { default=${2:-"y"} - default=$(echo "$default" | tr '[:upper:]' '[:lower:]') + default=$(printf "%s" "$default" | tr '[:upper:]' '[:lower:]') # Set prompt string case "$default" in y) prompt="Y/n" ;; n) prompt="y/N" ;; - *) echo "Invalid default answer"; exit 1 ;; + *) printf "Invalid default answer\n"; exit 1 ;; esac while true; do - echo -n "$1 ($prompt): " + trap 'stty sane; exit' INT + printf "%s (%s): " "$1" "$prompt" stty raw -echo answer=$(head -c 1) || exit stty -echo @@ -28,9 +29,7 @@ ask_yn() { done case "$answer" in - y|Y) echo 1;; - n|N) echo 0;; + y|Y) printf "1";; + n|N) printf "0";; esac -} - -ask_yn "$@" \ No newline at end of file +} \ No newline at end of file