[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Syntax regarding "Exec" instruction in .desktop files



Hi,

Could someone explain to me the correct syntax (quoting & escaping) regarding "Exec" instruction in .desktop files please?

The FreeDesktop specification (https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s07.html) says the following:

===BEGIN EXTRACT===
"Arguments may be quoted in whole. If an argument contains a reserved character the argument must be quoted. The rules for quoting of arguments is also applicable to the executable name or path of the executable program as provided.

Quoting must be done by enclosing the argument between double quotes and escaping the double quote character, backtick character ("`"), dollar sign ("$") and backslash character ("\") by preceding it with an additional backslash character. Implementations must undo quoting before expanding field codes and before passing the argument to the executable program. Reserved characters are space (" "), tab, newline, double quote, single quote ("'"), backslash character ("\"), greater-than sign (">"), less-than sign ("<"), tilde ("~"), vertical bar ("|"), ampersand ("&"), semicolon (";"), dollar sign ("$"), asterisk ("*"), question mark ("?"), hash mark ("#"), parenthesis ("(") and (")") and backtick character ("`").

Note that the general escape rule for values of type string states that the backslash character can be escaped as ("\\") as well and that this escape rule is applied before the quoting rule. As such, to unambiguously represent a literal backslash character in a quoted argument in a desktop entry file requires the use of four successive backslash characters ("\\\\"). Likewise, a literal dollar sign in a quoted argument in a desktop entry file is unambiguously represented with ("\\$")."
===END EXTRACT===

I'm not sure to understand that totally...

Let's take an example, here is my fusuma.desktop file:[Desktop Entry]
Type=Application
Name=fusuma
Exec=sh -c 'if which ruby >/dev/null && which gem >/dev/null; then $(ruby -r rubygems -e "puts Gem.user_dir")/bin/fusuma -d; fi'
StartupNotify=false
Terminal=false

Actually, it WORKS on my Debian 10... but it's not considered as syntaxically correct:

desktop-file-validate fusuma.desktop 

fusuma.desktop: error: value "sh -c 'if which ruby >/dev/null && which gem >/dev/null; then $(ruby -r rubygems -e "puts Gem.user_dir")/bin/fusuma -d; fi'" for key "Exec" in group "Desktop Entry" contains a reserved character ''' outside of a quote
fusuma.desktop: error: value "sh -c 'if which ruby >/dev/null && which gem >/dev/null; then $(ruby -r rubygems -e "puts Gem.user_dir")/bin/fusuma -d; fi'" for key "Exec" in group "Desktop Entry" contains a reserved character '>' outside of a quote
fusuma.desktop: error: value "sh -c 'if which ruby >/dev/null && which gem >/dev/null; then $(ruby -r rubygems -e "puts Gem.user_dir")/bin/fusuma -d; fi'" for key "Exec" in group "Desktop Entry" contains a reserved character '&' outside of a quote
fusuma.desktop: error: value "sh -c 'if which ruby >/dev/null && which gem >/dev/null; then $(ruby -r rubygems -e "puts Gem.user_dir")/bin/fusuma -d; fi'" for key "Exec" in group "Desktop Entry" contains a reserved character '&' outside of a quote
fusuma.desktop: error: value "sh -c 'if which ruby >/dev/null && which gem >/dev/null; then $(ruby -r rubygems -e "puts Gem.user_dir")/bin/fusuma -d; fi'" for key "Exec" in group "Desktop Entry" contains a reserved character '>' outside of a quote
fusuma.desktop: error: value "sh -c 'if which ruby >/dev/null && which gem >/dev/null; then $(ruby -r rubygems -e "puts Gem.user_dir")/bin/fusuma -d; fi'" for key "Exec" in group "Desktop Entry" contains a reserved character ';' outside of a quote
fusuma.desktop: error: value "sh -c 'if which ruby >/dev/null && which gem >/dev/null; then $(ruby -r rubygems -e "puts Gem.user_dir")/bin/fusuma -d; fi'" for key "Exec" in group "Desktop Entry" contains a reserved character '$' outside of a quote
fusuma.desktop: error: value "sh -c 'if which ruby >/dev/null && which gem >/dev/null; then $(ruby -r rubygems -e "puts Gem.user_dir")/bin/fusuma -d; fi'" for key "Exec" in group "Desktop Entry" contains a reserved character '(' outside of a quote
fusuma.desktop: error: value "sh -c 'if which ruby >/dev/null && which gem >/dev/null; then $(ruby -r rubygems -e "puts Gem.user_dir")/bin/fusuma -d; fi'" for key "Exec" in group "Desktop Entry" contains a reserved character ')' outside of a quote
fusuma.desktop: error: value "sh -c 'if which ruby >/dev/null && which gem >/dev/null; then $(ruby -r rubygems -e "puts Gem.user_dir")/bin/fusuma -d; fi'" for key "Exec" in group "Desktop Entry" contains a reserved character ';' outside of a quote
fusuma.desktop: error: value "sh -c 'if which ruby >/dev/null && which gem >/dev/null; then $(ruby -r rubygems -e "puts Gem.user_dir")/bin/fusuma -d; fi'" for key "Exec" in group "Desktop Entry" contains a reserved character ''' outside of a quote

>From my understanding, I've tried:
Exec=sh -c "if which ruby \>/dev/null \&\& which gem \>/dev/null\; then \$\(ruby -r rubygems -e \"puts Gem.user_dir\"\)/bin/fusuma -d\; fi"

I get no warning except it does not work now!
It's probably a matter of successive backslashes but I don't understand how many are needed exactly...
Of course I'm interested in the correct syntax for my example but it's not so critical as it's already working.
I would rather be more interested if you could share with me your own understanding of the official spec, with 2 or 3 different examples so it's cristal clear :)

Thank you & Best regards,
l0f4r0


Reply to: