Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Linux environment variable for another user (sudo)

How can we set environment variables for another user on a machine? I want to run some script with sudo -u xyz but I need to set some environment variables before running the script for xyz user which is different from my login.

like image 578
TopCoder Avatar asked May 27 '11 07:05

TopCoder


1 Answers

You can add VAR=VALUE between the sudo -u xyz and the script. Example

sudo -u xyz LANG=C LD_LIBRARY_PATH=/usr/local/lib some_script.sh
like image 63
George Dimitrov Avatar answered Oct 12 '22 16:10

George Dimitrov