Score:2

How can I keep terminal running after closing app?

br flag

I created a desktop shortcut to run a script. However, I am not sure how I can keep terminal open once I close the app or if it crashes. I am fairly new to coding so please forgive me if this has been asked before. I tried other forums posts but I couldn't seem to get it to work for this one.

Name=Test
Comment=
Exec=bash -c "$HOME/test_folder/scripts/test.sh"
Icon=/usr/share/icons/test.png
Terminal=true
Type=Application
StartupNotify=true
Score:1
cn flag
  • On your Exec= line, remove the bash -c " and ¨ at the end: there is no need. Just directly specify the full pathname of your script if it is not in a directory in your PATH.
  • Edit your script, and add a line bash. that way, the terminal will stay open on a prompt after the previous command in the script has finished.
Score:1
cn flag

The terminal window cannot remain open without a program running in it. So in order to keep the terminal open you have to make sure the command running in it does not exit. There are various ways to achieve this. One aspect that needs consideration is when and how the terminal shall be closed eventually.

In your case, since your command is bash running a script which you control, perhaps the simplest solution is to add the line:

read -p "Press ENTER to continue"

to the end of that script. This will cause the script to wait for a line of input before exiting, so the terminal will only close when you hit the ENTER key while it has the focus.

If your Exec= line contains a command you cannot or do not want to modify then an alternative solution would be to append the read command to it, for example:

Exec=/bin/bash -c '/usr/local/bin/coolprog ; read -p "Press any key to continue"'

The terminal will start a shell to run this command line, and the read command will cause that shell to wait for a line of input before exiting.

br flag
This worked perfectly, thank you! I will now try experiment for terminal to ask to 'relaunch' instead of exiting out of terminal
vanadium avatar
cn flag
Good answer, but I don't think anyone tested the `Exec=` part.
vanadium avatar
cn flag
Good answer, but I don't think anyone tested the Exec= part. Anyway, I was under the impression that you rather wanted a terminal prompt after the app closes.
Tilman avatar
cn flag
You're right. An ill-conceived last moment edit. Sorry about that. Fixed.
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.