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.
如何为机器上的另一个用户设置环境变量?我想用sudo -u xyz运行一些脚本,但是在为xyz用户运行脚本之前,我需要设置一些环境变量,这与我的登录不同。
2 个解决方案
#1
1
From the env(1)
man page:
环境保护(1)手册页:
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.
#2
30
You can add VAR=VALUE between the sudo -u xyz
and the script. Example
您可以在sudo -u xyz和脚本之间添加VAR=VALUE。例子
sudo -u xyz LANG=C LD_LIBRARY_PATH=/usr/local/lib some_script.sh
#1
1
From the env(1)
man page:
环境保护(1)手册页:
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.
#2
30
You can add VAR=VALUE between the sudo -u xyz
and the script. Example
您可以在sudo -u xyz和脚本之间添加VAR=VALUE。例子
sudo -u xyz LANG=C LD_LIBRARY_PATH=/usr/local/lib some_script.sh