gnome-terminal --tab --title="watch reason" --command="bash -c 'yarn start'" 

Running this command would open up a new terminal an run the script start.

But on pressing control+c the terminal closes.

How can this be prevented so that pressing control+c would stop the script but the terminal does not close.

  • Create a terminal, then type in and run the command from within that terminal. May 23, 2020 at 14:44
  • @DougSmythies I have to run three npm scripts. So instead of manually doing that every time I thought a script would be helpful May 24, 2020 at 15:33

1 Answer 1


I also had this problem and the solution is to trap the Ctrl+C.

When Ctrl+C is pressed, you want the terminal to return to bash as if you had typed in the command manually. You can trap the Ctrl+C signal (INT) and run exec bash instead.

This would look like:

gnome-terminal --tab --title="watch reason" --command="bash -c 'endyarnstart() { exec bash; }; trap endyarnstart INT; yarn start;'"

This will call the function endyarnstart when you press Ctrl+C, which will start bash and the terminal will behave as normal from then on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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