Re: home directories...
Bradley Bell <bradleyb@u.washington.edu> writes:
On Sat, 28 Aug 1999, Oliver Elphick wrote:
> >What routines should one use when parsing /etc/passwd?
>
> awk -F: '{if ($3 > 999) print $1}' </etc/passwd
Yes, the idea is that it should work no matter where the home directories
are. I guess I'll probably go the awk route, but I thought there might be
a more standard way of doing it.
I don't like the idea of parsing /etc/passwd very much. The C library
provides routines for iterating /etc/passwd. What's more, they also
work if home directories are stored in NIS+ or whatever instead of
being in the actual /etc/passwd file. You should use them.
Perl has a simple interface to these functions. Use `perldoc -f
setpwent' for more information.
Example that prints all users names' along with their home
directories:
#! /usr/bin/perl
while (my ($user, $home) = (getpwent ())[0,7]) {
print "$user\t$home\n";
}
Reply to: