Perl 中的 getpwent函数

首页 / Perl入门教程 / Perl 中的 getpwent函数

描述

此函数从/etc/passwd文件返回下一个密码条目。它与setpwent和endpwent函数结合使用以遍历密码文件。在列表context中,返回

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

语法

以下是此函数的简单语法-

getpwent

返回值

此函数在标量context中返回用户名,并在列表context中返回用户记录(名称,密码,用户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";
}

执行上述代码后,将产生以下输出-

链接:https://www.learnfk.comhttps://www.learnfk.com/perl/perl-getpwent.html

来源:LearnFk无涯教程网

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

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

AI技术内参 -〔洪亮劼〕

Go语言核心36讲 -〔郝林〕

小马哥讲Spring核心编程思想 -〔小马哥〕

Web安全攻防实战 -〔王昊天〕

HarmonyOS快速入门与实战 -〔QCon+案例研习社〕

深入浅出分布式技术原理 -〔陈现麟〕

深入浅出可观测性 -〔翁一磊〕

零基础GPT应用入门课 -〔林健(键盘)〕

深入拆解消息队列47讲 -〔许文强〕

好记忆不如烂笔头。留下您的足迹吧 :)