How to get another user’s PATH in Bash on Linux?
Posted on In QAHow 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
.