TopCoder
TopCoder

Reputation: 4296

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.

Upvotes: 13

Views: 17853

Answers (2)

George Dimitrov
George Dimitrov

Reputation: 3139

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

Upvotes: 35

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798746

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.

Upvotes: 0

Related Questions