我总是忘记如何在 Perl 中做到这一点。这是我的脚本:
#!/usr/local/bin/perl -w
use strict;
use Data::Dumper;
my @got = getpwent();
my $username = ${[getpwent()]}[0];
print Dumper( @got );
print "username is [$username]\n";
...这是它产生的输出...
$VAR1 = 'root';
$VAR2 = 'xxxxxxxxxxxxxxxxxx';
$VAR3 = 0;
$VAR4 = 0;
$VAR5 = '';
$VAR6 = '';
$VAR7 = 'myhost root';
$VAR8 = '/root';
$VAR9 = '/bin/bash';
username is [bin]
...我的问题是,为什么用户名等于“bin”而不是“root”?