Cover V02, I06
Article
Listing 1
Listing 2
Listing 3
Listing 4
Listing 5
Listing 6

nov93.tar


Listing 6: askyn

###########################################
#
#  askyn
#
#      usage:  askyn "<prompt>"
#
#  Prompts the user for a yes/no answer, using the given prompt.
#  Prompts are on stderr so that the response can be returned
#  on standard input -- intended for use with back-quote substitution.
#

prompt=$1

while true
do
echo "$prompt [y/n] > \c" >&2
read answer
answer=`echo $answer | tr "[a-z]" "[A-Z]"`
[ "$answer" = "N" -o "$answer" = "Y" ] && echo
$answer && exit
echo "Please enter \"y\" or \"n\"." >&2
done