當前位置:首頁 » Perl » Perl getpwnam()函數

Perl getpwnam()函數

perl getpwnam()函數,getpwnam()函數學習例子,getpwnam()函數實例代碼,getpwnam()函數教學等

語法

getpwnam EXPR


定義和使用

在列表上下文中,返回的字段列表,如在etc/passwd文件中提取,根據EXPR通過指定的用戶名。它通常是這樣的:

($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwnam ($user);

在標量上下文中,返回的用戶ID數字。如果您正在嘗試訪問整個/etc/passwd文件,你應該使用的getpwent函數。如果你想訪問用戶ID的詳細信息,請使用getpwuid

返回值

  • 在標量上下文用戶ID

  • 在列表上下文中的用戶記錄 (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) = getpwnam("root");
   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