I wrote a little bash script that opens a new gnome-terminal window. In that window, I need it to run an app which receives some input from the keyboard and produces some output that I want to observe. If the app receives "ex" as the input, it exits. To prevent the terminal from closing immediately when "ex" is the input, I managed to keep it opened with this:

gnome-terminal -- /bin/bash -c "${PATH_TO_APP}; exec /bin/bash -i"

But if I kill the app with Ctrl+C, that terminal will close. How can I keep that terminal window opened when I hit it with a Ctrl+C?

1 Answer 1


Short answer - add an empty trap handler that catches CTRL+C and does nothing instead of exit:

gnome-terminal -- /bin/bash -c "trap '' INT; ${PATH_TO_APP}; exec /bin/bash -i"

If you need more details on how to handle traps, distinguish between user inputs and interrupts, click here

  • unfortunately this doesnt seem to work with ubuntu 22.04 :(
    – alilland
    May 24 at 3:03

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.