Definition of command line in the Exec key
Simon McVittie
smcv at collabora.com
Thu Mar 23 12:24:56 UTC 2017
On Mon, 20 Mar 2017 at 05:09:19 +0300, Роман Чистоходов wrote:
> Should it be considered shell command line
No, the content of Exec= is not a one-line shell script. If you need
to use shell constructs like if...fi, ``, ${} then you must invoke a
shell yourself:
Exec=sh -c "if foo; then bar; else baz; fi"
> or something that can be called via execve.
You can't directly pass the value of the Exec key to execve, because
it's a single string and execve wants an array of strings, but it's close.
To parse an Exec value, you must unquote it according to the generic
.desktop file syntax, then break it into an array at unquoted whitespace,
then undo shell-style quoting within each entry of that array.
The desktop entry spec does describe this, although from the perspective
of a .desktop file author (there are many of those) rather than from the
perspective of an implementor (there are only a few of those).
GLib's g_shell_parse_argv() is one common C implementation of those
operations; there is another in dbus-daemon.
(For a general implementation you also need to expand *field codes* like %f,
some of which expand to more than one argument in the output argv. In GLib
this is done in a different layer - see GDesktopAppInfo for an implementation.)
> Giving that desktop-file-validate does not like unquoted backticks I would say
> the latter, but all this stuff about quotation rules makes me think about the
> former.
> This is probably due the legacy code that makes behavior of Exec similar to the
> one if this command line was to be run in shell.
It is essentially a subset of /bin/sh syntax. I believe the intention
is that every Exec value that is valid according to the Desktop Entry
Specification has the same meaning in /bin/sh and in a spec-compliant
.desktop file parser. However, many Exec values are not considered valid,
and would produce different results from g_shell_parse_argv() and a full
/bin/sh shell; it is probably not considered to be a bug in GLib's
g_shell_parse_argv(), KDE's equivalent, your equivalent, etc. if they
produce different results for an invalid .desktop file.
S
More information about the xdg
mailing list