此函数从/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
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
HarmonyOS快速入门与实战 -〔QCon+案例研习社〕