Skip to content

Instantly share code, notes, and snippets.

@caelor
caelor / ask.sh
Last active August 29, 2015 14:11
Bash "ask" function, modified to force reading from controlling terminal. This makes it suitable for using in "while read line; do ... done < $(file)" loops (that direct the file into stdin)
# This is a general-purpose function to ask Yes/No questions in Bash, either
# with or without a default answer. It keeps repeating the question until it
# gets a valid answer.
ask() {
# http://djm.me/ask
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"