描述
此函數返回 /etc/passwd 文件中的下一個密碼條目。這與 setpwent 和 endpwent 函數結合使用以迭代密碼文件。在列表上下文中,返回
($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwent;
用法
以下是此函數的簡單語法 -
getpwent
返回值
此函數返回標量上下文中的用戶名和列表上下文中的用戶記錄(名稱、密碼、用戶 ID、組 ID、引號、評論、真實姓名、主目錄、shell)。
示例
以下是顯示其基本用法的示例代碼 -
#!/usr/bin/perl
while(($name, $passwd, $uid, $gid, $quota, $comment, $gcos,
$dir, $shell) = getpwent()) {
print "Name = $name\n";
print "Password = $passwd\n";
print "UID = $uid\n";
print "GID = $gid\n";
print "Quota = $quota\n";
print "Comment = $comment\n";
print "Gcos = $gcos\n";
print "HOME DIR = $dir\n";
print "Shell = $shell\n";
}
執行上述代碼時,會產生以下結果 -
Name = root Password = x UID = 0 GID = 0 Quota = Comment = Gcos = root HOME DIR = /root Shell = /bin/bash Name = bin Password = x UID = 1 GID = 1 Quota = Comment = Gcos = bin HOME DIR = /bin Shell = /sbin/nologin . . . Name = com Password = x UID = 501 GID = 501 Quota = Comment = Gcos = HOME DIR = /home/com Shell = /bin/bash Name = railo Password = x UID = 497 GID = 495 Quota = Comment = Gcos = HOME DIR = /opt/railo
相關用法
- Perl getpwnam用法及代碼示例
- Perl getpwuid用法及代碼示例
- Perl getprotoent用法及代碼示例
- Perl getpeername用法及代碼示例
- Perl getprotobynumber用法及代碼示例
- Perl getprotobyname用法及代碼示例
- Perl getservent用法及代碼示例
- Perl getnetbyname用法及代碼示例
- Perl getnetent用法及代碼示例
- Perl gethostent用法及代碼示例
- Perl getgrnam用法及代碼示例
- Perl getsockopt用法及代碼示例
- Perl getgrgid用法及代碼示例
- Perl getgrent用法及代碼示例
- Perl getservbyname用法及代碼示例
注:本文由純淨天空篩選整理自 Perl getpwent Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。