I'm writing a script that supposed to be ran with sudo permissions.
But then I need to execute a command from an another user sourcing it's .bash_rc where there are some env variables are overloaded and then use it in a command.
For example. I need to print the PATH variable for the user:
sudo -s -u ${USER_NAME} source ~/.bash_rc; echo $PATH
But instead it prints PATH for a user running the script.
I've also tried a lot of other options (with su or passing a rcfile) but none of them seems to work.
How could I deal with it?
.bash_rc, and if you meant.bashrcthen you shouldn't define environment variables there.