How to Access Another User’s PATH in Bash
When running scripts as root, you often need to execute commands with the environment of a different user. The most reliable way to retrieve another user’s PATH is by spawning a login shell under that user’s context. Basic Approach user1path=$(su – user1 -c ‘echo $PATH’) This spawns a login shell (-) as user1 and outputs…
