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!

4

2 回答 2

10

这是如何知道用户是否选择了转义:

read -s -n1  key

 case $key in
     $'\e') echo "Escape";;
 esac
于 2013-07-14T11:21:55.833 回答
1

如果您最终使用 bash shell,您可能对“trap”命令感兴趣,它允许您捕获并处理中断(例如 ctrl-C)

例如: http://kb.mit.edu/confluence/pages/viewpage.action?pageId= 3907156

于 2013-07-14T15:04:50.117 回答