开发者

Setting Linux environment variable for another user (sudo)

开发者 https://www.devze.com 2023-03-08 14:08 出处:网络
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

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

精彩评论

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