LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   how to get $HOME for the login user ID when "su" has been used (http://www.linuxquestions.org/questions/programming-9/how-to-get-%24home-for-the-login-user-id-when-su-has-been-used-633532/)

kornelix 04-06-2008 05:35 PM

how to get $HOME for the login user ID when "su" has been used
 
I need to get the home directory of the login user ID as opposed to the effective user ID (which changes when "su" is used). I can get the login user ID ($USERNAME) but I cannot find a way to get the home directory of a known user that is not the current user. I need a shell command like the c-lib getpwent() function. It must be there somewhere but I cannot find it.

blacky_5251 04-06-2008 06:43 PM

Try this:-
Code:

grep $LoggedInUser /etc/passwd | cut -f 6 -d ":"
Where $LoggedInUser holds the value of the user that logged in - not the su'ed user id.

kornelix 04-07-2008 03:39 AM

Thank you blacky!!

kornelix 04-07-2008 03:45 AM

$LoggedInUser is not defined on my system (Ubuntu) but $USERNAME works.

matthewg42 04-07-2008 04:01 AM

Try using "su -" which will execute the shells login rc files and provide a login-like shell environment.

Having said that, on my debian box, su always sets HOME, no matter if I use the "-" method or not.


All times are GMT -5. The time now is 01:58 AM.