Copyright © tutorialspoint.com

PERL getpwent Function


Syntax

getpwent


Definition and Usage

Returns the next password entry from the /etc/passwd file. This is used in combination with the setpwent and endpwent functions to iterate over the password file. In a list context, returns

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

Return Value

  • In scalar context user name

  • In list context user record (name, password, user ID, group ID, quote, comment, real name, home directory, shell)

Example

Try out following example:

#!/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";
}


Copyright © tutorialspoint.com