getpwuid EXPR |
在列表上下文中,返回字段列表,如在/etc/passwd文件中提取,根據EXPR通過指定的用戶名。 它通常是這樣的:
($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid ($uid);
在標量上下文中返回用戶名。如果要嘗試訪問整個/etc/passwd文件, 應該使用getpwent函數,如果想訪問用戶名,那麼可以使用getpwnam。
在標量上下文中的用戶名稱
在列表上下文中的用戶記錄(name, password, user ID, group ID, quote, comment, real name, home directory, shell)
試試以下實例:
#!/usr/bin/perl
#by www.gitbook.net
($name, $passwd, $uid, $gid, $quota,
$comment, $gcos, $dir, $shell) = getpwuid(0);
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";
// It will produce following result
Name = root
Password = *******
UID = 0
GID = 0
Quota =
Comment =
Gcos = root
HOME DIR = /root
Shell = /bin/bash