getgrnam
优质
小牛编辑
129浏览
2023-12-01
描述 (Description)
此功能按组名称查找组文件条目。 在列表上下文中返回以下内容 - ($name, $passwd, $gid, $members)
$ members标量包含一个以空格分隔的登录名列表,这些登录名是该组的成员。 返回标量上下文中的组名。 有关检索整个组文件的更有效方法,请参阅getgrent。 在Windows下,请考虑使用Win32API :: Net模块。
语法 (Syntax)
以下是此函数的简单语法 -
getgrnam NAME
返回值 (Return Value)
此函数返回scalr上下文中的组名称以及列表上下文中的名称,密码,组ID和成员列表。
例子 (Example)
以下是显示其基本用法的示例代码 -
#!/usr/bin/perl
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 = bin
Password = x
GID = 1
Members =
Name = daemon
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 = apache
Password = x
GID = 48
Members =
Name = rexx
Password = x
GID = 1001
Members =
Name = objc
Password = x
GID = 1002
Members =