DEV Community

Reprise Software
Reprise Software

Posted on

How Environment Variables Work Across Shells (And How to Set Them Right)

Environment variables are dynamic flags set outside an application that the application then reacts to. Applications and libraries like RLM read environment variables that they define and rely on them to control runtime options, such as:

  • RLM_ACT_TIMEOUT (adjusts the timeout to the activation server to the value supplied)
  • RLM_QUEUE (enables queueing for a license)
  •  RLM_ROAM (controls setting up, using, and returning roamed licenses)

The Environment Process

A defining characteristic of environment variables is that they are scoped to the specific process where they are set (like a Windows command window or a Unix/Linux shell), and are inherited only by processes that are created by that process. Meaning: if you create 2 command windows and you set an environment variable in window 1, it won't be set in window 2. But if you run an application in window 1, the environment variable will be set in that application.

Easiest Way to Set an Environment Variable
Set it in a command window or shell, then invoke the application from that window or shell.  For example, if you wanted to set RLM_DIAGNOSTICS to cause the application to write RLM diagnostic information to the file diag.txt, you would:

  • Windows: set RLM_DIAGNOSTICS=diag.txt
  • sh, bash: export RLM_DIAGNOSTICS=diag.txt
  • csh: setenv RLM_DIAGNOSTICS diag.txt

Then invoke the application from the window where you set RLM_ROAM.

What if your App isn’t Launched from a Terminal?
In this case, you can set the environment variable via the Windows control panel:

  • Bring up the control panel
  • Search for “environment” in the search box at the top right
  • Click on "Edit environment variables” for your account
  • Enter the environment variable name and value
  • Click on OK in both windows

Top comments (0)