示例
以下是显示其基本用法的示例代码-
while( ($name,$passwd,$gid,$members) = getgrent() ) {
print "Name = $name\n";
print "Password = $passwd\n";
print "GID = $gid\n";
print "Members = $members\n";
}
setgrent(); # Set the beginnging of the group database;
print "Again reading /etc/passwd file\n";
while( ($name,$passwd,$gid,$members) = getgrent() ) {
print "Name = $name\n";
print "Password = $passwd\n";
print "GID = $gid\n";
print "Members = $members\n";
}
endpwent; #claose the database;
尝试一下
执行以上代码后,将产生以下结果--
Name = root
Password = x
GID = 0
Members =
Name = daemon
Password = x
GID = 1
Members =
Name = bin
Password = x
GID = 2
Members =
Name = sys
Password = x
GID = 3
Members =
Name = adm
Password = x
GID = 4
Members =
Name = tty
Password = x
GID = 5
Members =
Name = disk
Password = x
GID = 6
Members =
Name = lp
Password = x
GID = 7
Members =
Name = mail
Password = x
GID = 8
Members =
Name = news
Password = x
GID = 9
Members =
Name = uucp
Password = x
GID = 10
Members =
Name = man
Password = x
GID = 12
Members =
Name = proxy
Password = x
GID = 13
Members =
Name = kmem
Password = x
GID = 15
Members =
Name = dialout
Password = x
GID = 20