May 12, 2022    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 [[ $do_backup =~ ^(y|Y|)$ ]]  # Do if 'y' or 'Y' or empty
then
    echo "doing backup"
fi

gist