Greetings c,
What others have posted already would be smarter than what I'm going to suggest. However, in the interests of contribution of all ideas, even ones that are fairly basic, here's another option:
#!/usr/bin/perl -w
use strict;
my $group_name = 'monks';
open(GROUPS, '/etc/group');
my $gid = (split /:/, (grep /^$group_name:/, <GROUPS>)[0])[2];
close GROUPS;
print $gid, "\n";
exit;
Using getgrnam is a much better option, though. My way here assumes way too much and could therefore fail in many situations.
-gryphon
code('Perl') || die;
|