Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following bash compound command:

while true ; do slow-command-one ; slow-command-two ; slow-command-three ; done

What happens:

  • When I press CtrlC at any point, the entire command is aborted.

What I want to happen:

  • When I press CtrlC during execution of slow-command-two, slow-command-two should be aborted, and execution should continue with slow-command-three.
  • When I press CtrlC at any other time, the entire command should be aborted (as now).

How do I get this to happen?

share|improve this question
Ctrl-C is SIGINT. – Ignacio Vazquez-Abrams Nov 5 '10 at 11:03
Ta, have edited. – dave4420 Nov 5 '10 at 11:09
up vote 5 down vote accepted

You can use trap command for that. Catch SIGINT with it and Ctrl+C does not hurt your command execution. Then reset trap to default settings.

This should work:


while true; do
  trap "echo Proceeding to command three" SIGINT;
  trap - SIGINT;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.