I would like to know how to write the Exec
command of a .desktop file to open a new terminal and execute a shell script in it. The shell script is working and accessible by all users. When launching the script from the terminal everything works, but it doesn't when trying to launch the script from a .desktop file.
Here are some combinations I have already tried:
Exec=gnome-terminal -x sh -c 'echo hello'
Exec=sh -c 'gnome-terminal echo hello'
Exec=sh -c 'echo hello'
Exec=echo hello
The .desktop terminal option is set to true.
The content of your desktop file should look like (see how to create a .desktop file using a text editor):
Or:
In the first case, the
Terminal
field is set tofalse
(perhaps contrary to your expectations) and in second case is set totrue
, but the result is in both cases the same.Make the above file. Don't forget to
sudo chmod +x filename.sh
Simply add
at the end of your commands.
Like for me
snapd
isn't something using full bandwidth of system to refresh snaps anytime almost I work at night.So this worked for me to create a
.sh
file linked to a.desktop
file.Contents for
.sh
file were-S
in the first line of the.sh
file is used to sendSTDINPUT
to thesudo
command meaning direct execute without entering password.Contents for the
.desktop
file were:TL;DR
As stated in desktop entry specification,
Terminal=true
tells the launcher to launch your script in a terminal window. The chosen Terminal Emulator depends on your default applications settings and Desktop Environment. In GNOME, it is gnome-terminal, in KDE, it is Konsole. (Without DE, in plain WM there is a bug in xdg-open, andTerminal=true
just ignored, see issue)You need this line to run your script and launch a shell after it.
sh -c 'COMMAND'
run the "sh" binary found in $PATH which executes COMMAND (on many systems,sh
is the symbolic link tobash
, but for portability "sh" is prefered)echo hello; $SHELL
does two things. First, it runsecho hello
and then, after the execution of this command, launches $SHELL.If you will not add some command that waits for you to exit, a terminal emulator will just run your program and exit.
P.S. If you just want not to close your terminal, you can do
Or
(read will wait for you to press Enter, sleep will just wait 5 seconds)
P.P.S
$SHELL
probably will be the same as last section in/etc/passwd
in line with your user.I do this. First line of the text file is !#/bin/bash
Subsequent lines of the text file are the commands (the shell script).
Save the file as something.sh
Open the properties of the file and enable run file as a program.
Now, when the file is double clicked, I get the option to run it.