开发者

Setting Linux environment variable for another user (sudo)

How can we set environment va开发者_开发百科riables 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.


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


From the env(1) man page:

NAME
       env - run a program in a modified environment

SYNOPSIS
       env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]

DESCRIPTION
       Set each NAME to VALUE in the environment and run COMMAND.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜