Desktop configuration for shell script fails to launch

KDE Plasma Version 5.12.8

I have a test shell script that works when I right-click on the file in Dolphin and select “Run in Konsole.”

I have attempted to add an entry to the KDE application launcher, but the script fails to complete after a brief flash of what I suspect is the console. I have tried modifying the settings in the KDE Menu Editor and the .desktop file directly, but without success.

Here is the script:

#! /bin/sh
ls

Here is the .desktop file:

[Desktop Entry]
Comment=
Exec=/root/bin/ls.sh
Name=ls.sh
NoDisplay=false
Path$e]=$HOME/bin
StartupNotify=true
Terminal=1
TerminalOptions=
Type=Application
X-KDE-SubstituteUID=false
X-KDE-Username=

Images of the menu editor dialog are at: https://susepaste.org/92103549 and https://susepaste.org/23777159.

The code appears to have the same syntax as other suggestions on this forum, but I am unable to determine where the error lies. (E.g., https://forums.opensuse.org/showthread.php/514482-Can-I-Create-a-desktop-Launcher-For-a-Shell-Script).

I may be missing something, but when you execute a script (or any program) “in a console”, I assume that a terminal emulator (probably konsole in KDE) is started where this program is then a child process. When there is any ouput to stdout or stderr, you will see that text in the console and when it reads from stdin, I guess it waits until you type ending with a return. And when the program exits, I would expect the console also exiting.

Thus when you only have some output (of the ls command) that will be put to the console and then the console will disapear. All in a wink (ecept when the ls listing is very long and you will see it flashing by).

As you told things happened to your satisfaction when using Dolpin > Right-click on file > Actions > Execute in Konsole, I tried that also. To my surprise the Konsole window shows the output and then stays on the screen??? I could not exit in the normal way (Ctrl-C and/or Ctrl-D), thus I had to kill the window (not the neatest way of working).

Next step was checking what is running. From the ps -ef listing:

henk     29716 27951  0 21:25 ?        00:00:00 /usr/bin/konsole --hold -e /home/henk/test/script

So, Dolpfin uses the --hold option.
Next step is of course to check the documentation of Konsole:

–hold, --noclose
Do not close the initial session automatically when it ends.

There is however no explanation how to stop then in a neat way.

My conclusion, to achieve what you probably want, you must add the --hold option somewhere in the call to konsole.

Henk -

Thank you!! That’s it! Adding --noclose in the menu dialog did it. I now read up on the options (and what they mean!): https://docs.kde.org/trunk5/en/applications/konsole/command-line-options.html

Here are the menu dialog: https://susepaste.org/53774442 and the resulting konsole held open: https://susepaste.org/1655266

Here is the output from ps -ef:

20356 20226  0 15:50 ?        00:00:00 /usr/bin/konsole --hold -e /root/bin/ls.sh

The .desktop file now reflects the terminal option:

[Desktop Entry]
Comment=
Exec=/root/bin/ls.sh
Name=ls.sh
NoDisplay=false
Path$e]=$HOME/bin
StartupNotify=true
Terminal=1
TerminalOptions=--noclose
Type=Application
X-KDE-SubstituteUID=false
X-KDE-Username=

And, more importantly, I now know that the test script works and can thus write further actual scripts. (This was my first.)

Thanks for the prompt reply and the education - much appreciated as always.

You are welcome.

Btw, it depends on what you are doing, but a simple

read

as last statement of the script wil let the whole thing wait on a hit on the Return key. Will also work on other terminal emultaors, I do not know if xterm has a --hold lookalike.

Thank you. I just tried the “read” command at the end of the script, removing the --noclose terminal option, and I like that better for this purpose. It provides confirmation of the execution and then closure by hitting return.

Thanks again.

Yes, just end your script with someting like

echo "When you have read all the above, please hit the return key with your fingertip (NO HAMMER!)"
read

rotfl!

Henk -

Thank you.