Desktop Application with File with Environment Variable

Desktop Application with File with Environment Variable

Context

  • XFCE4

Issue

Trying to run a software with a bunch of environment's variables stored into a file named prod.env, directly from autostart.

Here is the content of the .desktop file stored at /home/user/.config/autostart/player.desktop :

[Desktop Entry]
Encoding=UTF-8
Name=blablabla
Comment=
Path=/appli/player/
Exec=/bin/bash /appli/player/run.sh start
Terminal=false
Type=Application

According to documentation, there is no field related to this feature.

Have you a trick that allow to run a program with an environment variables file, using autostart ?

1 Answer

First, make sure that /appli/player/run.sh is executable and has an appropriate shebang line, so that it can be run directly (without /bin/bash). Then change the Exec line to

Exec=/bin/sh -c '. path/to/prod.env && /appli/player/run.sh start'

This will source the prod.env file, making its contents available in the environment in which /appli/player/run.sh start is executed.

You can replace /bin/sh with /bin/bash if you prefer, but sh is a lighter shell.

Your Answer

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

Marcus Vance
Author

Marcus Vance

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.