Interview Prep/Shell Scripting/Arguments, I/O, here-docs, process substitution and subshells

How do you read user input with a timeout and a default value?

BeginnerConceptArguments, I/O, here-docs, process substitution and subshells
Answer
read -r -t 10 -p "Proceed with prod deploy? [y/N] " answer || answer=n
case ${answer,,} in
  y|yes) deploy ;;
  *)     echo "aborted"; exit 1 ;;
esac

-t returns a status greater than 128 on timeout. In CI or cron there is no terminal; check with [[ -t 0 ]] and require a --yes flag instead of prompting.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Arguments, I/O, here-docs, process substitution and subshells