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.


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 Commented Dec 20, 2014 at 10:55

2 Answers 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
    Commented Dec 21, 2014 at 1:32
  • What about for Icon=? Commented Aug 4, 2018 at 5:13

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'


  • 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 # ...


! 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


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .