Wednesday, May 8, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 806  / 2 Years ago, sun, august 21, 2022, 11:41:05

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

More From » command-line

 Answers
0

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.


[#974] Tuesday, August 23, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
llael

Total Points: 209
Total Questions: 102
Total Answers: 118

Location: Rwanda
Member since Fri, May 5, 2023
1 Year ago
llael questions
Fri, May 19, 23, 07:42, 1 Year ago
Sun, Dec 11, 22, 02:43, 1 Year ago
Tue, May 18, 21, 06:06, 3 Years ago
Sat, Oct 16, 21, 08:01, 3 Years ago
;