I'm trying to check whether the current shell session is running within a su login session.
What's the best way to test this condition?
|
I'm trying to check whether the current shell session is running within a What's the best way to test this condition? |
|||||
|
|
look into the
This example if from Mac OS X, so the use of the By using logname, you can assume that if the user returned by the |
|||||||||
|
|
If you want to test whether the current shell was executed by
If you want to test whether the user called |
|||
|
|
Here's one solution I wired up:
pstree with the -p flag lists the ancestry tree of the current shell process PID ($$) grep finds lines containing "root su" (I'm using the [r] trick to avoid returning the grep process itself) sed cleans up the result and prints just the current username at the end of the line. (It would be more helpful if it would print the user of the parent process though.) |
|||
|
|