This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: "which" command does not expand "~" in path

you wrote:

> On Mon, 27 Sep 2004, Sven Köhler wrote:
>>>> But is there any command that give's me the home for a given
>>>> username?
>>> bash -c "echo ~username"
>> Oh well, beside bash (and any other big programm called shell)
>>> Or you could write one using the getpwnam() call (better yet, the
>>> reentrant versions, getpwnam_r()), and submit it to, say, cygutils
>>> (since sh-utils is no longer being actively developed).
>> I just wondered how to write a "correct" shell-script that runs with
>> /bin/sh, and it seems there is no way "shell-script"-way to figure
>> out a  user's homedir.
> You could try
> awk -F: "/^username:/"'{print $6}' < /etc/passwd
> (the pattern is in double quotes so that variable substitution can
> occur, e.g., you could change "username" to "$1" in a shell script).
> Igor --

$ u="Hannu";sed -nre "s/^$u.*:(.*):.*$/\1/p" </etc/passwd

I bet there are some more other ways to do it... ;-P

/Hannu E K Nevalainen, B.Sc. EE Microcomputer systems            --72-->

** mailing list preference; please keep replies on list **

-- printf("LocalTime: UTC+%02d\n",(DST)? 2:1); --

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]