Bash Yes No Prompt: 7 Proven Patterns and 5 Mistakes
A bash yes no prompt is a read -r -p "Question? [y/N] " ans followed by a case on the answer. The short version that most tutorials show works for a quick test, but it treats "yolo" as yes, loops forever when there is no terminal and silently skips the question when the script is piped. This guide shows a confirm function that handles all of that, plus Yes/No/Cancel, single-key answers, timeouts, select menus and unattended runs with -y . Every example was run on 2026-10-23 in a debian:trixie container with GNU bash 5.2.37 and dash as /bin/sh . The answers were typed on a real pseudo-terminal (util-linux script ), so the output below is exactly what a user sees at each bash yes no prompt, including the typed answer. Contents The classic bash yes no prompt and its problems A reusable bash yes no prompt function with a default Bash yes no prompt with Cancel in a loop Single key, timeout and select menu Bash yes no prompt in pipes, cron and CI POSIX sh version ...