当前位置:首页 » 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