How to get another user's PATH in Bash on Linux?

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

asked Apr 6, 2016 by anonymous

1 Answer

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.

answered Apr 26, 2016 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...