I have as script that requires root privileges. I run the script using
sudo ./script.sh. Some parts of the script need to actually run as the original user, so I use
sudo --user=$SUDO_USER inside the script to do that work. The problem I'm having is that I have some utilities installed for the user, and their path is appended to $PATH in my
~/.profile. I get the feeling that ~/.profile is not executed when running as sudo, confirmed by
sudo --user=$SUDO_USER echo $PATH.
I can get around this by sourcing $HOME/.profile, but this doesn't seem like the right solution:
sudo --user=$SUDO_USER source $HOME/.profile; command_i_want_to_run
Should I be appending my $PATH in a different file in order to make it available no matter the context?