Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out which environment variables used by a command

In a Linux environment (in my case XUbuntu), is there a way to find out which environment variables are accessed by a command which is run from the console?

It must be possible to find out about these variables, as someone has to provide the values to the program. But is there some default method to do this?

The program in question here is xprintidle.

like image 346
Jost Avatar asked Dec 13 '11 18:12

Jost


People also ask

How do I check environment variables in CMD?

To Check if an Environment Variable ExistsSelect Start > All Programs > Accessories > Command Prompt. In the command window that opens, enter echo %VARIABLE%. Replace VARIABLE with the name of the environment variable.

How do I get a list of environment variables?

You can open a Command Prompt, type set , and press Enter to display all current environment variables on your PC. You can open PowerShell, type Get-ChildItem Env: , and press Enter to display all current environment variables on your PC.

How do I check environment variables in Unix?

You can view all environment variables set on your system with the env command.


1 Answers

Assuming you want the variables actually used by some process running a command, you could use ltrace and look for calls to getenv:

$ ltrace -e getenv ./your_program

Of course, the argument to getenv can be computed (so you cannot really predict it).

However, some (old or strange) applications might use the environ global, or the third optional argument to main; and some applications even change their environment using putenv, setenv or unsetenv (all 3 being the libc functions, not the shell builtin).

but xprintidle is mostly interacting with the Xorg server. I'm surprised you are expecting it to use many environment variables (except DISPLAY).

like image 55
Basile Starynkevitch Avatar answered Sep 21 '22 12:09

Basile Starynkevitch