描述
此函數將枚舉設置(或重置)到密碼條目集的開頭。這個函數應該在第一次調用 getpwent 之前調用。
用法
以下是此函數的簡單語法 -
setpwent
返回值
此函數不返回任何值。
示例
以下是顯示其基本用法的示例代碼 -
#!/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";
}
setpwent() ; # Rewind the databse /etc/passwd
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";
}
endpwent(); # Closes the database;
執行上述代碼時,會產生以下結果 -
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 = daemon Password = x UID = 2 GID = 2 Quota = Comment = Gcos = daemon HOME DIR = /sbin Shell = /sbin/nologin . . . Name = qemu Password = x UID = 107 GID = 107 Quota = Comment = Gcos = qemu user HOME DIR = / 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 Shell = /bin/false
相關用法
- Perl setpriority用法及代碼示例
- Perl setprotoent用法及代碼示例
- Perl sethostent用法及代碼示例
- Perl setgrent用法及代碼示例
- Perl setsockopt用法及代碼示例
- Perl setnetent用法及代碼示例
- Perl setservent用法及代碼示例
- Perl semget用法及代碼示例
- Perl send用法及代碼示例
- Perl seekdir用法及代碼示例
- Perl semctl用法及代碼示例
- Perl semop用法及代碼示例
- Perl select用法及代碼示例
- Perl sin()用法及代碼示例
- Perl split用法及代碼示例
- Perl shmctl用法及代碼示例
- Perl splice用法及代碼示例
注:本文由純淨天空篩選整理自 Perl setpwent Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。