6

I can add env in .desktop file in /usr/share/applications/

Exec=env FOO=bar /usr/bin/my_prog

but I need to set 2 environment variables and no approach that I tried works (using env twice, appending second assignment after ;)

How can I set 2 env variables in .desktop file ?

user
  • 94
  • 1
  • 4
  • 17
Martin Vegter
  • 69
  • 66
  • 195
  • 326
  • 3
    The [documentation for env](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/env.html) says that `name=value` can be repeated. Did you try `Exec=env FOO=bar SNA=fu /usr/bin/myprog` ? – Mark Plotnick Jul 29 '18 at 12:10
  • @Mark Plotnick - yes I have tried that. but only the first variable has effect. The second is ignored – Martin Vegter Jul 29 '18 at 12:15
  • 2
    Cannot reproduce this and for me it works with `Exec=env foo=bar bar=foo /home/user/test/test.sh`. Where `test.sh` echos the two variables `foo` and `bar`. You might want to write a wrapper script as an alternative and call that wrapper script in your `.desktop` entry. – Thomas Jul 29 '18 at 12:27
  • 1
    Do your environment variable values contain any blanks or other non-alphanumeric characters? – Mark Plotnick Jul 29 '18 at 13:31
  • @MarkPlotnick Besides setting up multiple env vars, I have a special case where my environment variable value itself contains an `=` sign. How to escape it? – Koder101 Sep 11 '21 at 06:54

1 Answers1

4

As mentioned above, your variant with the addition of several variables should work correctly

Exec=env FOO=bar /usr/bin/my_prog

So either there is some kind of external factor, or the question is not fully correct

lucidyan
  • 160
  • 5
  • Besides setting up multiple env vars, I have a special case where my environment variable value itself contains an `=` sign. How to escape it? – Koder101 Sep 11 '21 at 06:54
  • `FOO=foo=bar HELLO=hello=world && printf "$FOO $HELLO\n"` working fine in bash, but you can also quote values for safety – lucidyan Sep 12 '21 at 21:56