示例
以下是显示其基本用法的示例代码-
while( ($name,$passwd,$gid,$members) = getgrent() ) {
($name,$passwd,$gid,$members) = getgrnam $name;
print "Name = $name\n";
print "Password = $passwd\n";
print "GID = $gid\n";
print "Members = $members\n";
}
尝试一下
执行结果:
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
Members =
Name = fax
Password = x
GID = 21
Members =
Name = voice
Password = x
GID = 22
Members =
Name = cdrom
Password = x
GID = 24
Members =
Name = floppy
Password = x
GID = 25
Members =
Name = tape
Password = x
GID = 26
Members =
Name = sudo
Password = x
GID = 27
Members =
Name = audio
Password = x
GID = 29
Members =
Name = dip
Password = x
GID = 30
Members =
Name = www-data
Password = x
GID = 33
Members =
Name = backup
Password = x
GID = 34
Members =
Name = operator
Password = x
GID = 37
Members =
Name = list
Password = x
GID = 38
Members =
Name = irc
Password = x
GID = 39
Members =
Name = src
Password = x
GID = 40
Members =
Name = gnats
Password = x
GID = 41
Members =
Name = shadow
Password = x
GID = 42
Members =
Name = utmp
Password = x
GID = 43
Members =
Name = video
Password = x
GID = 44
Members =
Name = sasl
Password = x
GID = 45
Members =
Name = plugdev
Password = x
GID = 46
Members =
Name = staff
Password = x
GID = 50
Members =
Name = games
Password = x
GID = 60
Members =
Name = users
Password = x
GID = 100
Members =
Name = nogroup
Password = x
GID = 65534
Members =
Name = input
Password = x
GID = 101
Members =
Name = systemd-journal
Password = x
GID = 102
Members =
Name = systemd-timesync
Password = x
GID = 103
Members =
Name = systemd-network
Password = x
GID = 104
Members =
Name = systemd-resolve
Password = x
GID = 105
Members =
Name = systemd-bus-proxy
Password = x
GID = 106
Members =
Name = ssh
Password = x
GID = 107
Members =