Is this a correct way for passing an environment variable in sudo ?
sudo -u www-data -b env FOOBAR="foobar" /home/user/folder/daemon
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
That works, but env isn’t needed. You can run a test like this:
/tmp/test:
#!/bin/sh echo $tst
chmod +x /tmp/test
sudo tst=howdy /tmp/test
It’s also possible to get environment variables through using the -E option, which preserves your environment (depending on other settings).
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