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 // ?!
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.Sign up to join this community
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"