I am trying to run a script as another user, with the user's .bashrc properly loaded (it is a python script and it relies on $PYTHONPATH being properly set).
I tried everything I found for example here, but the best I could coax out of the system was an empty $PYTHONPATH (which is better than my original, where it actually used my $PYTHONPATH).
The usecase is that I'm teaching students about shebangs and paths and whatnot, and I wanted an automated way of checking whether their script are ok or not. I can check them by dropping into their envs with sudo su <username>, but that is very tedious.
How can I execute a script as another user, with their environment loaded the same as if I used sudo su <username> and then ran it myself?
-c "echo $PYTHONPATH"I see my ownPYTHONPATHnotsudo su -l <username> -c printenv– Michael D. Nov 06 '20 at 13:27.bashrcis showing up. – fbence Nov 09 '20 at 18:41.profileit does get set. I think I might be confused on what gets loaded when. – fbence Nov 09 '20 at 18:43sudo su <username>.profileis not loaded, but.bashrcis. – fbence Nov 09 '20 at 18:45