LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash - script not see environment variable running under sudo (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-not-see-environment-variable-running-under-sudo-4175411733/)

jfjh201 06-16-2012 02:25 AM

bash - script not see environment variable running under sudo
 
step1.sh
Quote:

#!/bin/bash


echo ${myvar}
Quote:

jfjh@jfjh-pc:/mnt/gentoo/home/jfjh/lfs-scripts$ export myvar=100
jfjh@jfjh-pc:/mnt/gentoo/home/jfjh/lfs-scripts$ ./step1.sh
100
jfjh@jfjh-pc:/mnt/gentoo/home/jfjh/lfs-scripts$ sudo ./step1.sh

jfjh@jfjh-pc:/mnt/gentoo/home/jfjh/lfs-scripts$
os is ubuntu 12.04

Tinkster 06-16-2012 08:23 PM

Hi, welcome to LQ!

sudo, by default, doesn't preserve the environment.

Try running w/ sudo -E


For details:
Code:

man 5 sudoers
/env_reset

Cheers,
Tink


All times are GMT -5. The time now is 01:41 PM.