Listing 13
# ask user a yes/no question
# return Y on std output if answer is yes, else N.
# usage: ask "string"
# ( " (y/n)? " automatically appended)
if [ $# -ne 1 ]
then
echo "$0: usage: $0 <string>" >&2
exit
fi
while true
do
echo "$1 (y/n)? \c" >&2
read answer
case $answer in
n|N) echo "N"
break;;
y|Y) echo "Y"
break;;
*) echo "Please answer 'y' or 'n'..." >&2
esac
done
|