Sudo and Environment Variables
I have always been scratching my head whenever I used sudo and the environment variables (env) keep on changing. In my case, I have learned there are two ways to keep/preserve the environment or retain some them when moving into a privilege account (sudo -s).
First method, run
#sudo -s -E
where the -E parameter is meant to presserve the environment.
Second method, save all necessary variables in the current user (not root) shells profile (i.e. for bash its ~/.bashrc) and save these environment variables.
#vi ~/.bashrc
export param1=value1
export param2=value2
#
That’s all to it.