Keep terminal open after bash script launch from desktop

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
SemiSolidState
Level 1
Level 1
Posts: 21
Joined: Wed Dec 09, 2020 11:59 am

Keep terminal open after bash script launch from desktop

Post by SemiSolidState »

Bash script on my desktop, 2x Click, select 'Run in Terminal', gnome-terminal opens and script runs. The last item executed is a python script that runs forever and occasionally displays things. If I Ctrl-C kill it then the terminal closes. Instead I want the terminal to stay open (drop to a shell prompt) because sometimes I modify the python script, Ctrl-C it, then re-launch it.

Alternatively I tried having my bash script launch a new terminal window for the Python script but got the same result in that I was unable to keep that terminal window from closing once the python script is killed. I searched it up and tried many things, I can't recall them all.

I also tried having the bash script launch a terminal window then use xdotool to send keys to launch the python script but the keys never hit the terminal, I think for security reasons.

Any suggestions?
Last edited by LockBot on Mon Aug 07, 2023 10:00 pm, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
vimes666
Level 6
Level 6
Posts: 1241
Joined: Tue Jan 19, 2016 6:08 pm

Re: Keep terminal open after bash script launch from desktop

Post by vimes666 »

Ending your script with command bash should keep it open although you would really be in a child process of the shell where you started in.
If you think the issue is solved, edit your original post and add the word solved to the title.
User avatar
xenopeek
Level 25
Level 25
Posts: 29615
Joined: Wed Jul 06, 2011 3:58 am

Re: Keep terminal open after bash script launch from desktop

Post by xenopeek »

So use exec bash, that replaces the running shell with the command to execute — it this case an interactive shell.
Image
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Keep terminal open after bash script launch from desktop

Post by rene »

A note; poster talks about ending the script with here Ctrl-C, i.e., before it ever gets to either a bash or exec bash. Currently on Xfce and I don't see such available in its configuration but if not mistaken then gnome-terminal has or at least once had a "keep terminal open after program exits" switch somewhere.
User avatar
xenopeek
Level 25
Level 25
Posts: 29615
Joined: Wed Jul 06, 2011 3:58 am

Re: Keep terminal open after bash script launch from desktop

Post by xenopeek »

It's a bash script that launches a Python script. The Ctrl+C should interrupt the Python script, returning control to the bash script. So doing a exec bash after the Python script invocation should work.
Image
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Keep terminal open after bash script launch from desktop

Post by rene »

Sure. In any case I suggest checking your terminal options; Cinnamon uses gnome-terminal.
vimes666
Level 6
Level 6
Posts: 1241
Joined: Tue Jan 19, 2016 6:08 pm

Re: Keep terminal open after bash script launch from desktop

Post by vimes666 »

if not mistaken then gnome-terminal has or at least once had a "keep terminal open after program exits" switch somewhere.
In mate there is such an option in the terminal profile setting, but it doesn't seem to make any difference.
If you think the issue is solved, edit your original post and add the word solved to the title.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Keep terminal open after bash script launch from desktop

Post by rene »

Then that's yet another instance where I might as well have not noted such...
vimes666
Level 6
Level 6
Posts: 1241
Joined: Tue Jan 19, 2016 6:08 pm

Re: Keep terminal open after bash script launch from desktop

Post by vimes666 »

Well it does make a difference but not the difference you want.
If you think the issue is solved, edit your original post and add the word solved to the title.
Locked

Return to “Scripts & Bash”