Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
$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
    
Does $ ./print.sh (without sudo) shows value ? –  Didier Trosset Oct 27 '11 at 11:55
add comment

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

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

1 Answer

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.