如何在c-shell脚本中执行可中断步骤后立即阻止中断

时间:2018-06-28 14:14:38

标签: csh

RHEL6上的C-shell

我想防止^ C中断阻止c-shell脚本中的某个步骤运行。问题是我希望用户能够使用^ C来中断之前的步骤...

#!/usr/bin/env tcsh
# Run the next step, allow ^C interrupt
step1
# I always want to respond to what happened in step1 by running step2
onintr -
step2
onintr
echo "The end"

我对此的实验失败了。显然,第1步的多个连续^ C中断转入了shell并中断了shell脚本,然后才使“ onintr-”生效。同样,我不能将“ onintr-”放在步骤1之前,因为我希望用户能够中断该步骤。

有没有办法做到这一点?

预先感谢

1 个答案:

答案 0 :(得分:0)

我想我可以用标签来完成我想要的...

#!/usr/bin/env tcsh
# Run the next step, allow ^C interrupt
onintr gohere
step1
# I always want to respond to what happened in step1 by running step2
:gohere
step2
onintr
echo "The end"