描述
此函數按組名查找組文件條目。在列表上下文中返回以下內容 - ($name, $passwd, $gid, $members)
$members 標量包含作為組成員的登錄名的空格分隔列表。返回標量上下文中的組名。有關檢索整個組文件的更有效方法,請參閱 getgrent。在 Windows 下,考慮使用 Win32API::Net 模塊。
用法
以下是此函數的簡單語法 -
getgrnam NAME
返回值
此函數返回標量上下文中的組名稱和列表上下文中的名稱、密碼、組 ID 和成員列表。
示例
以下是顯示其基本用法的示例代碼 -
#!/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 =
相關用法
- Perl getgrgid用法及代碼示例
- Perl getgrent用法及代碼示例
- Perl getpwnam用法及代碼示例
- Perl getservent用法及代碼示例
- Perl getnetbyname用法及代碼示例
- Perl getprotoent用法及代碼示例
- Perl getnetent用法及代碼示例
- Perl gethostent用法及代碼示例
- Perl getsockopt用法及代碼示例
- Perl getpeername用法及代碼示例
- Perl getprotobynumber用法及代碼示例
- Perl getservbyname用法及代碼示例
- Perl getpwent用法及代碼示例
- Perl gethostbyaddr用法及代碼示例
- Perl getnetbyaddr用法及代碼示例
注:本文由純淨天空篩選整理自 Perl getgrnam Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。