I put some script on my ubuntu linux in /etc/profile.d/myscript.sh but it's just work on my user.

But it's work only user logged in not when I use sudo.

# myscript.sh
export MYVAL="HELLO"

echo $MYVAL // HELLO

sudo echo $MYVAL // ?!

Could you please explain better what are you trying to achieve? .profile is executed with a user privileges, when the user logs on.
So in order to use sudo in .profile you have to put user/group, user belongs to in /etc/sudoers

ok, sudo strips environment variables for various security reasons. In order to do what you want, you have to put in /etc/sudoers

Defaults        env_reset  
Defaults        env_keep += "MYVARIABLE YETANOTHER"
| improve this answer | |
  • i need to define a variable that can i use in each user with and without sudo. it's so simple. – sweb Nov 5 '12 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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