Web lists-archives.com

Re: Get Cygwin home directory path for current user




On 2/14/2019 3:57 PM, Vince Rice wrote:
>> On Feb 14, 2019, at 5:41 PM, Bill Stewart wrote:
>>     
>> (?) I understand that the shell does ~ expansion....
>>     
>
> It would not appear that you do. You asked why a Cygwin shell would be a prerequisite.
>   
----
    Vince, I think What Bill is trying to ask is how does
the cygwin shell might do it (answer: look at the source! ;-)).


    Bill, I may not be able to say w/certainty, and Brian Inglis's
post show various linux + Windows ways of getting it.  In the absence
of some language, I used something like:

  $home = $ENV{HOME} ||
          $ENV{USERPROFILE} ||
          $ENV{HOMEDRIVE}.$ENV{HOMEPATH};

  A little bit of programming, like in perl would find it:

perl -e 'printf "home=%s\n", getpwnam($ENV{USER});' 

The perl docs tell you the "get" calls mirror the C calls.
Likely a shell written in 'C' uses one of those calls.

Unfortunately, its not just as simple as checking
/etc/passwd these days (though it seems that is what the call
is doing) -- various user-management systems do it different
ways...like NIS/YP (NetworkInformationSystems/YellowPages) on linux
or AD(Active Directory) on Windows, which was derived from
MIT's Kerberos.

Notice on cygwin (or linux) the file
/etc/nsswitch.conf, which says:

#    This file is read once by the first process in a Cygwin process tree.
#    To pick up changes, restart all Cygwin processes.  For a description
#    see https://cygwin.com/cygwin-ug-net/ntsec.html#ntsec-mapping-nsswitch
#
# Defaults:
# passwd:   files db
# group:    files db
# db_enum:  cache builtin
# db_home:  /home/%U      ;<<-- cygwin's default that shell will return
# db_shell: /bin/bash
# db_gecos: <empty>

In this case it looks like the answer to your question,
BY DEFAULT, is to use the string /home/%U, where %U = your windows
username. 

Now you can go read the webpage if you want more info, but
hopefully this answers at least a bit of your question?

When addressing technical people, you need to know
how to ask the right (or rightly phrased) questions.

Also note, that most of the 'standard answers appear not
to apply' in cygwin -- just tack '/home/ on the front
of your username.




--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple