On Slackware, using sbopkg permits one to build a package from source. Repos is not big as Debian, but it’s nice.
Some software can use environment variables,
for example on the VICE c64 emulator, if the variable
FFMPEG is set to yes, it will enable ffmpeg recording the emulator.
I tried to use
$ export FFMPEG=yes; sudo sbopkg -B -i vice
but ffmpeg is disabled.
Instead I had to use
$ su - $ export FFMPEG=yes $ sbopkg -B -i vice
which works.
How to use environment variables with sudo?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You may use sudo’s -E option:
FMPEG=yes sudo -E sbopkg -B -i vice
From the manual:
-E, –preserve-env
Indicates to the security policy that the user wishes to
preserve their existing environment variables. The security
policy may return an error if the user does not have permission
to preserve the environment.
Note that this exports all your existing environment variables. It is safer to only export the environment variables you need with the following syntax:
sudo FMPEG=yes sbopkg -B -i vice
Method 2
sudo sanitizes the variables in the environment before invoking the given command. You will have to ask it to preserve the variables in the environment for your command to work.
Additionally, you will have to export the FMPEG variable before using sudo (export FMPEG=yes; sudo), assign it in the same go as invoking sudo (FMPEG=yes sudo), or use env (env FMPEG=yes sudo).
To preserve the environment variables, use -E (or --preserve-env):
$ env FMPEG=yes sudo -E sbopkg -B -i vice
It’s also possible to set specific environment variables like this:
$ sudo FMPEG=yes sbopkg -B -i vice
If this fails due to the security policy in place, bring up a root shell and set the variable there:
$ sudo -s # env FMPEG=yes sbopkg -B -i vice # exit
Method 3
note that:
(export a=b; command) is equivalent to a=b command. Note the brackets.
Then if we apply the variable not to sudo but direct to sbopkg,
so instead of FFMPEG=yes sudo sbopkg -B -i vice
we can do
sudo FFMPEG=yes sbopkg -B -i vice
If a security police prevent this, then:
sudo bash -c "FFMPEG=yes sbopkg -B -i vice"
(Don’t use -E, it us insecure as it will leak all sorts of unexpected variables.)
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0