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.
More on Arguments, I/O, here-docs, process substitution and subshells
How does `getopts` work? Show a complete example.IntermediateWhat is the difference between `getopts` and `getopt`?AdvancedExplain file descriptors 0, 1 and 2 and the main redirection operators.BeginnerWhy is `cmd 2>&1 > file` different from `cmd > file 2>&1`?AdvancedWhat is a here-document, and what is the difference between `<<EOF`, `<<'EOF'` and `<<-EOF`?BeginnerWhat is a here-string (`<<<`)?Intermediate