getgrent
优质
小牛编辑
131浏览
2023-12-01
描述 (Description)
此函数迭代/ etc/group文件中的条目。 在列表上下文中返回以下内容 -
($ name,$ passwd,$ gid,$ members)
$ members标量包含一个以空格分隔的登录名列表,这些登录名是该组的成员。 仅在标量上下文中使用时返回组名。 在Windows下,请考虑使用Win32API :: Net模块。
语法 (Syntax)
以下是此函数的简单语法 -
getgrent
返回值 (Return Value)
此函数在scalr上下文和列表上下文中返回组名称(名称,密码,组ID和成员列表。
例子 (Example)
以下是显示其基本用法的示例代码 -
#!/usr/bin/perl
while( ($name,$passwd,$gid,$members) = getgrent() ) {
print "Name = $name\n";
print "Password = $passwd\n";
print "GID = $gid\n";
print "Members = $members\n";
}
执行上述代码时,会产生以下结果 -
Name = root
Password = x
GID = 0
Members = root
Name = bin
Password = x
GID = 1
Members = root bin daemon
Name = daemon
Password = x
GID = 2
Members = root bin daemon
Name = sys
Password = x
GID = 3
Members = root bin adm
Name = adm
Password = x
GID = 4
Members = root adm daemon
Name = tty
Password = x
GID = 5
Members =
.
.
.
Name = fuse
Password = x
GID = 496
Members =
Name = kvm
Password = x
GID = 36
Members = qemu
Name = qemu
Password = x
GID = 107
Members =
Name = com
Password = x
GID = 501
Members =
Name = webgrp
Password = x
GID = 502
Members = com
Name = railo
Password = x
GID = 495
Members =