The python language has a built-in facility to prompt & read in one motion ...
Bash does not ... you kinda need to prompt, then read, using the "echo -n" and "read" functions.
See sample script and output below - it reflects the requirements you suggest in the question.
typeset -l ans ## forces lower case
prompt="Go Forward? (yes, no, cancel) : "
action=
ansFlag=0
while (( ansFlag == 0 )) ## keep prompting until the user gets it right ...
do
echo -n "$prompt"
read ans
case "$ans" in
"yes")
action="Yes Action"
ansFlag=1
;;
"no")
action="No Action"
ansFlag=1
;;
"cancel")
action="Action Action"
ansFlag=1
;;
*)
echo "Invalid Response" >&2
;;
esac
done
echo "Performing: $action"
exit 0
And this is a sample interaction with the script ...
$ ./readit
Go Forward? (yes, no, cancel) :
Invalid Response
Go Forward? (yes, no, cancel) : kjkj
Invalid Response
Go Forward? (yes, no, cancel) : yes
Performing: Yes Action