How do sudo environment variables work in linux?
问题 I'm currently perplexed by the following: sudo echo $MYVAR outputs my variable from my .bashrc, but sudo ./test.sh does not, where test.sh is the below executable: #!/bin/sh echo $MYVAR I'm running Ubuntu 14.04. Can someone enlighten me as to what's going on here? 回答1: When you run sudo echo $MYVAR , the environment variable is expanded in your shell ... before the sudo command gets to see it. When you run a script using sudo , that script only sees the environment variables that sudo has