2022-05-12    Share on: Twitter | Facebook | HackerNews | Reddit

Bash - Continue, Yes or No

do_backup=y                      # In batch mode => Default is Yes
-t 0 &&                     # If TTY => Prompt the question
read -r -n 1 -p $'\e[1;32m
Continue with backup? (Y/n)\e[0m ' do_backup  # Store the answer in $do_xxxx
if Y|)$  # Do if 'y' or 'Y' or empty
then
 echo "doing backup"
fi