Search code examples
cenvironment-variablessudogetenv

Sudo environment variable


I want to create an environment variable and set it in sudo, I mean, I want it to be in sudo printenv but I just can put it in printenv.

I am making a program and I need to run the program with sudo and inside I use getenv(), but running the program with sudo it does not work properly.

Does anyone know how to help me?


Solution

  • You can set it right before executing the command. For example:

    sudo A=B printenv