Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
$cat test
export var=value

$source ./test

$cat print.sh
echo $var

$chmod +x print.sh

$echo $var
value

$sudo ./print.sh

I get nothing. I was expecting to see value.

What is going on?

share|improve this question

migrated from stackoverflow.com Oct 28 '11 at 2:06

This question came from our site for professional and enthusiast programmers.

    
Does $ ./print.sh (without sudo) shows value ? – Didier Trosset Oct 27 '11 at 11:55
up vote 5 down vote accepted

if you want to keep the environment with a sudo, use sudo -E that will preserve environment.

If you need to always preserve some of your environment variables, edit the sudoers file to add lines :

Defaults        env_reset
Defaults        env_keep += "YOURVARIABLE OTHERVARIABLE YETANOTHER"
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .