How can you determine if a user pressed the enter key?
Hello All,
I'm new to the scripting world, and I am trying to do something that should I thought would be trivial but I seem to be running into some difficulty. Basically I have a Bash script which is prompting a user for a key. Sounds like a simple task, but if a user presses the enter key I would like to use a default value. Unfortunately I can not seem to distinguish between an enter key, a space, backspace, delete. Below is my code snippet, any help you can provide would be greatly appreciated.
------ Begin Code Snippet --------
echo "Would you like to do something? [Y]:
read -n 1 answer
if [ "$answer" == "y" ] || [ "$answer" == "Y" ]
then
echo "User would like to do something"
else
echo "User did NOT want to do something"
exit 1
fi
------ End Code Snippet --------
It seems that when ever a enter key(carriage return, space, backspace, delete...etc) my return value stored is a NULL character.
So basically I am just looking is someone knows of a way way to determining if a user pressed the Enter Key?
|