Confirm a yes/no prompt
Print a message and return 0 on y/yes, 1 otherwise (default N).
18th August 2026
confirm() {
local answer
printf "%s [y/N]: " "$1"
read -r answer || true
case "${answer}" in
y|Y|yes|YES) return 0 ;;
*) return 1 ;;
esac
}
Caveats
Empty input or anything other than y/yes is treated as no.