0

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

0

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .