/etc/profile
is only executed for interactive shells.
One way to fix this is to add this to the beginning of /tmp/printmyname.sh
:
. /etc/profile
Note that this may cause problems because /etc/profile
tries to set up an interactive environment, so a lot of setup scripts will be called that you may not want.
A better solution is probably to put this variable in a new global script and source this new script from both /etc/profile
and /tmp/printmyname.sh
Related articles: