From 52fbb147708a035e53ba35f46e0bfbadf8dc8acf Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 3 Jun 2021 13:28:29 +0200 Subject: [PATCH] add timeout to interactive example --- examples/question.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/question.sh b/examples/question.sh index d20b4ba..a908abd 100755 --- a/examples/question.sh +++ b/examples/question.sh @@ -10,7 +10,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.5-0-g8adca9b +#### $$VERSION$$ v1.51-dev-24-gc63f098 ######################################################################## ###### @@ -29,6 +29,10 @@ export 'LANGUAGE=C.UTF-8' unset IFS # set -f # if you are paranoid use set -f to disable globbing +# kill interactive script if not finished in time, e.g. user away or error +MAXWAIT="1m" +{ sleep "${MAXWAIT}"; printf "Stopping Questionnaire after %s, you need to much time to finish ... BYE\n" "${MAXWAIT}"; kill $$; wait 2>/dev/null ;} & + # simple yes/no question, defaults to no printf "Hi, hello there\nWould you like some tea (y/n)?\n" read -r answer <"${INPUT}"