Score:0

Keep gnome-terminal from closing when opened from bash script

mn flag

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?

Score:0
in flag

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

alilland avatar
kz flag
unfortunately this doesnt seem to work with ubuntu 22.04 :(
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.