I have this simple command to check if a file exists:
if [ -f /tmp/file.txt ] ; then echo "yes" ; else echo "no" ; fi
If I run it direcly on terminal, it works (shows "yes" if the file exists and "no" if it doesn't). But I want to execute this command inside a .desktop
file using it as a value to Exec
key:
[Desktop Entry]
Version=1.0
Type=Application
Exec=if [ -f /tmp/file.txt ] ; then echo "yes" ; else echo "no" ; fi
StartupNotify=true
Terminal=false
Categories=Utility;X-XFCE;X-Xfce-Toplevel;
MimeType=x-scheme-handler/custom
Name=Custom Test
Comment=Custom
If I try to execute xdg-open custom://
I get custom://: error opening location: The specified location is not supported
, but if I change Exec
value to echo "yes"
and execute xdg-open custom://
, it shows yes
on terminal.
What am I missing here?
You are trying to execute shell script coding in .desktop file which is not supported.
The reason why "echo yes" worked is .desktop executes the echo command with paramter as "yes" which is acceptable.
.desktop executes commands along with options and parameters. You can write the shell script code in a .sh file and mentioned it in Exec or Run the code using
Exec=sh -c "if [ -f /tmp/file.txt ] ; then echo 'yes' ; else echo 'no' ; fi"
Here .desktop executes "sh" with options and params