2 # Author: Noah Friedman <friedman@prep.ai.mit.edu>
4 # Last modified: 1993-03-01
7 # Conversion to bash v2 syntax done by Chet Ramey
13 # Usage: y_or_n_p QUERY
15 # Print QUERY on stderr, then read stdin for a y-or-n response. Actually,
16 # user may type anything they like, but first character must be a `y', `n',
17 # `q', or `!', otherwise the question is repeated until such an answer is
20 # If user typed `y', y_or_n_p returns 0.
22 # If user typed `n', y_or_n_p returns 1.
24 # If user typed `!', y_or_n_p returns 2. This is an indication to the
25 # caller that no more queries should be made. Assume `y' for all the rest.
27 # If user typed `q', y_or_n_p returns 3. This is an indication to the
28 # caller that no more queries should be made. Assume `n' for all the rest.
37 [ ! -t 0 ] && return 1
39 while read -p "$*" -e ans
; do
45 *) echo "Please answer one of \`y', \`n', \`q', or \`"\
!"'" 1>&2 ;;
50 #:docstring yes_or_no_p:
51 # Usage: yes_or_no_p QUERY
53 # Like y_or_n_p, but require a full `yes', `no', `yes!', or `quit' response.
57 function yes_or_no_p
()
61 [ ! -t 0 ] && return 3
63 while read -p "$*" -e ans
; do
64 ans
="$(echo ${ans} | tr '[A-Z]' '[a-z]')"
71 *) echo "Please answer \`yes', \`no', \`yes"\
!"', or \`quit'" 1>&2 ;;
78 # y_or_n_p.bash ends here