How to get the $PATH environment variables of another user in Bash on Linux? The current user running the Bash script is root.

If the scripts is run by root, this piece of code will store the PATH from the environment of the user user1:

user1path=$(su - $user1 -c env | grep ^PATH= | cut -d'=' -f2-)

It runs env command as the $user to print out its environment and find out the $PATH.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *