8

I want to create a poll in a shell script:

echo "1 - What is your name?"
read name
echo "your name is $name"

echo "2 - What is your country?"
read country
echo "your country is $country"
...
...etc...
...

I want if the user press ESC in a question, cancel the question an jump to the next question.

Thanks! I keep in wait for possibles answers!

Manuel
  • 97
  • 1
  • 7

2 Answers2

11

this is how to know if user selected escape :

read -s -n1  key

 case $key in
     $'\e') echo "Escape";;
 esac
Nimrod007
  • 9,825
  • 8
  • 48
  • 71
1

If you end up using bash shell, you might be interested in the "trap" command, which allows you to trap and act on interupts (e.g. ctrl-C)

E.g: http://kb.mit.edu/confluence/pages/viewpage.action?pageId=3907156

fig
  • 732
  • 1
  • 8
  • 14