File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 11#
22# You may add more commands/functions here.
33#
4+
5+ ask_yesno () {
6+ while true ; do
7+ read -p " Do you want to continue? (y/n): " yesno
8+ case $yesno in
9+ [Yy]* )
10+ echo " You chose Yes. Proceeding..."
11+ true
12+ ;;
13+ [Nn]* )
14+ echo " You chose No. Exiting."
15+ false
16+ ;;
17+ * ) echo " Invalid input. Please answer 'y' or 'n'." ;;
18+ esac
19+ done
20+ }
21+
22+ ask_yesno_timeout () {
23+ local timeout=" ${1:- 10} "
24+ local msg=" ${2:- Do you want to continue? (Y/ n): } "
25+ echo " Please enter Y or N within $timeout seconds:"
26+ read -t $timeout -p " $msg " yesno
27+
28+ if [ $? -eq 0 ]; then
29+ # User entered input within the timeout
30+ case $yesno in
31+ [Yy]* )
32+ echo " You chose Yes. Proceeding..."
33+ true
34+ ;;
35+ [Nn]* )
36+ echo " You chose No. Exiting."
37+ false
38+ ;;
39+ * ) echo " Invalid input. Please answer 'y' or 'n'." ;;
40+ esac
41+ else
42+ # Timeout occurred or read failed for another reason
43+ true
44+ fi
45+ }
You can’t perform that action at this time.
0 commit comments