Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access an environment variable in a .desktop file's exec line?

Tags:

My program requires an environment variable as part of one of its parameters:

myprogram --folder=$HOME/.special 

However, if I put this into a .desktop file's exec line, it doesn't work:

Exec=myprogram --folder=$HOME/.special 

The $HOME seems to resolve to nothing.

like image 757
Scott Ritchie Avatar asked Jan 24 '12 00:01

Scott Ritchie


People also ask

How do I access environment variables?

Type sysdm. cpl into the input field and hit Enter or press Ok. In the new window that opens, click on the Advanced tab and afterwards on the Environment Variables button in the bottom right of the window.

How do I reference an environment variable from the command line?

To list all the environment variables, use the command " env " (or " printenv "). You could also use " set " to list all the variables, including all local variables. To reference a variable, use $varname , with a prefix '$' (Windows uses %varname% ).

What is the command to view an environment variable?

To display the values of environment variables, use the printenv command. If you specify the Name parameter, the system only prints the value associated with the variable you requested.


1 Answers

By default environment variables do not seem to be resolved by all implementations, however you can instead exec sh, which will resolve the passed environment variable. Note that the desktop spec also requires you to escape the = and $ character with a backslash. So you want:

Exec=sh -c "myprogram --folder\=\$HOME/.special" 

For the full list of characters that need escaping, see the specification

like image 174
Scott Ritchie Avatar answered Sep 22 '22 16:09

Scott Ritchie