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.Related posts:How to get the directory path and file name from a absolute path in Bash on Linux? How to get the directory path and file name from a absolute path in C on Linux How to test whether PATH has a specific directory in it in Bash on Linux? How to remove trailing / in path in Bash? How to find Linux absolute path for a relative path How to get the script’s own path in sourced Bash script? How to Get Bash Script’s Own Path How to move all the files under Users for a user to another drive on Windows?