Definition of command line in the Exec key
Oswald Buddenhagen
oswald.buddenhagen at gmx.de
Tue Mar 28 08:51:05 UTC 2017
On Thu, Mar 23, 2017 at 12:24:56PM +0000, Simon McVittie wrote:
> 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.
>
actually, it is in a way, as you're saying yourself further down.
and in kde, it is even in fact - the evaluator is smart enough to use an
actual shell if the command gets too complex. but relying on that is
obviously unportable.
> 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"
>
this is actually horrible advice, as it is pretty much guaranteed to
overtax the automatic quoting of expandos inside the nested command.
if you need a compound command, ship an _actual_ script and have the
.desktop file invoke it.
> 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.
>
indeed, which makes it a "shell script", albeit a rather limited one.
> 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.
>
i tend to agree with that, though i find it unfortunate that the shared
subset which is considered valid is comparably small.
fwiw, the kde implementation can be found in
https://code.woboq.org/qt5/kf5/kio/src/core/desktopexecparser.cpp.html
the underlying magic happens in
https://code.woboq.org/qt5/kf5/kcoreaddons/src/lib/util/kshell_unix.cpp.html
https://code.woboq.org/qt5/kf5/kcoreaddons/src/lib/text/kmacroexpander_unix.cpp.html
and there is an evolved version of the latter, which i shamelessly stole
from myself in
https://code.woboq.org/qt5/qt-creator/src/libs/utils/qtcprocess.cpp.html
(i still didn't manage to upstream it into qt proper ...)
More information about the xdg
mailing list