【发布时间】:2012-10-07 19:07:22
【问题描述】:
我正在尝试使用 read 在脚本中执行命令,当用户使用 Ctrl+C 时,我想停止命令的执行,但是不退出脚本。 像这样的:
#!/bin/bash
input=$1
while [ "$input" != finish ]
do
read -t 10 input
trap 'continue' 2
bash -c "$input"
done
unset input
当用户使用 Ctrl+C 时,我希望它继续读取输入并执行其他命令。问题是当我使用如下命令时:
while (true) do echo "Hello!"; done;
Ctrl+C按一次就不行了,但是按几次就可以了。
【问题讨论】:
标签: bash