#! /bin/sh default="$2" while : do echo "$1 [$default]? " | tr -d '\012' >/dev/tty # portable echo -n read answer case "$answer" in '') answer="$default" ;; esac case "$answer" in n*|N*) answer=no ;; y*|Y*) answer=yes ;; esac case "$answer" in !*) cmd="`expr \"$answer\" : '!\(.*\)'`" trap : 2 ${SHELL-/bin/sh} -c "$cmd" >/dev/tty trap 2 echo '!' >/dev/tty ;; yes|no) break ;; # NOTE BREAK OUT *) echo "please answer \`yes' or \`no'" >/dev/tty ;; esac done echo "$answer"