Perl getpwent 函式



說明

此函式從 /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_function_references.htm
廣告
© . All rights reserved.