From e5a32ee865c5324302bdf70906f322e88f8a58e3 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Fri, 31 May 2024 15:27:10 -0600 Subject: [PATCH] util for bash scripts --- util.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 util.sh diff --git a/util.sh b/util.sh new file mode 100644 index 0000000..fdc0fae --- /dev/null +++ b/util.sh @@ -0,0 +1,15 @@ +# prompt_char "prompt" +# Set REPLY to the next char the user types: +prompt_char () { + exec < /dev/tty + if [ ! -z "$2" ]; then + read -t $2 -p "${1} " -n 1 -r + else + read -p "${1} " -n 1 -r + fi + if [ $? -ne 0 ]; then + REPLY=n + fi + echo # (optional) move to a new line + exec <&- +} \ No newline at end of file