[TriLUG] Scripting question

Stephen P. Schaefer sschaefer at acm.org
Thu Jan 9 16:37:38 EST 2003


Your script is a bit different than what you say you want.  If I want a 
list of users with their home directories, I might do

awk -F":" '{ print $1,$6 }' /etc/passwd

If I wanted the home directory for a specific user, e.g., emma, I might do

userid="emma"
awk -F":" "/^$userid/ { print \$6 }" /etc/passwd

If you're trying to do something else, let us know.

     - Stephen

Janyne Kizer wrote:
> I am trying to get a list of home directories for regular users in a
> script.  The problem that I am running into is we have some cases where
> users with similar IDs are on the system.  For example, sa, saclark and
> sange or edware and dware.  On our test system we have emma and emma60. 
> Anyway, I am trying to do something similar to this:
> 
> for userid in `cat /etc/passwd | awk -F":" {'print $1'} | grep -xv
> "^the-stuff-we-don't-want"
> homedir=`grep $userid /etc/passwd | awk -F":"  {'print $6'}`
> 
> and of course it is returning two homedirs for emma (/home/emma and
> /home/emma60).  How can I get it to do an exact match?  From the command
> line this works:
> 
> grep '\<emma\>' /etc/passwd
> 
> but I must be doing something wrong with the escaping when I put it into
> a script.
> 
> Any suggestions would be appreciated!





More information about the TriLUG mailing list