3

I'm trying to make a .desktop file for Minecraft. Nothing appears to happen upon executing the file. I've tried assigning the Exec key as follows:

Exec= java -jar "~/.minecraft/Minecraft.jar"

Exec= java -jar "$HOME/.minecraft/Minecraft.jar"

But I'm not sure how to put in the reserved characters (~ and $) correctly. According to Freedesktop's Desktop Entry Specification:

If an argument contains a reserved character the argument must be quoted.

and

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.

But that's very confusing to me.

  • Desktop files have nothing to do with shell expansion. You must use absolute paths, e.g. java -jar /home/my_user_name/.minecraft/Minecraft.jar – don_crissti Dec 20 '14 at 10:55
2

It seems a common workaround to execute sh, which will resolve the special symbols and variables correctly:

Exec=sh -c "java -jar ~/.minecraft/Minecraft.jar"
  • 1
    Thank you. One thing though, the extra / doesn't seem to be necessary. This works: Exec=sh -c "java -jar ~/.minecraft/Minecraft.jar" – reggie-man Dec 21 '14 at 1:32
  • What about for Icon=? – Aaron Franke Aug 4 '18 at 5:13
-2

In your .desktop file write:

Exec=sh -c 'java -jar "$HOME"/.minecraft/Minecraft.jar'

Sample 2:

Exec=sh -c "u=%u; k=%k; c=%c;"' kd="$k"; [ -f "$kd" ] && kd=`dirname "$k"`; cd "$kd"; uxterm -bg blue -fg cyan3 -fn 9x15'

Explanation:

  • All terms like double-quote, quoting, meta-chars (like $ and ~) are always s h e l l - r e l a t e d - the shell (command-interpreter like bash or dash) is (by the way) independent from any terminal (like xterm).

  • When you want the tilde or the shell-var $HOME to be EXPANDED to sth. like /home/myloginname this can only be done by /bin/bash or /bin/sh (==/bin/dash).

  • The xdg-desktop-interpreter's Exec-line needs a real program (path-to-a-bin-file) and will never expand any shell-stuff directly, but by providing the sh-command with the option -c 'command-string; cmd... ; cmd...' all should work fine.

  • %u is a "xdg-placeholder" and is changed into DnD-URL independently (before the shell-command-line is executed)

  • Note that you can comment out lines in a .desktop file with # ...

P.S.:

! case   coproc   do  done elif else esac fi for function if in select
then until while { } time [[ ]]

are all "reserved words" (don't confuse this with the shell's built-in-cmds), but ~ and $ are meta-chars (the tilde must be un-quoted to be expanded, while $MYVAR may be quoted, if it contain SPACES inside a path)

kind regards EOF

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.