kamctl: kamdbctl.base - replaced get_answer() with a portable version
authorDaniel-Constantin Mierla <miconda@gmail.com>
Mon, 16 Sep 2019 08:12:47 +0000 (10:12 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Mon, 16 Sep 2019 08:12:47 +0000 (10:12 +0200)
- contributed by Sergey Safarov, GH #2019

utils/kamctl/kamdbctl.base

index 7029fd3..3846196 100644 (file)
@@ -205,16 +205,11 @@ merr() {
 #
 get_answer ()
 {
-    value=$1
-    question=$2
-    if [ "${value}" = "ask" ]; then
-        echo -n "$question"
-        read ANSWER
-    else
-        ANSWER=${value}
-    fi
-    ANSWER=${ANSWER:0:1}
-    ANSWER=${ANSWER/Y/y}
-    ANSWER=${ANSWER/N/n}
+       value=$1
+       question=$2
+       if [ "${value}" = "ask" ]; then
+               echo -n "$question"
+               read value
+       fi
+       ANSWER=$(echo ${value} | grep -o -e '[YyNn]' | sed -e 's/Y/y/' -e 's/N/n/')
 }
-