"Simple" but non-portable == useless.
Randal L. Schwartz
merlyn at iwarp.intel.com
Fri Feb 1 08:50:46 AEST 1991
In article <27A72A04.3BCA at tct.uucp>, chip at tct (Chip Salzenberg) writes:
| Here's my latest version, still only ten lines long (with closedir()),
| and with a better output format ("command dir1 dir2"):
|
| ===============================================================================
| for $dir (split(/:/, $ENV{'PATH'})) {
| opendir(DIR, length($dir) ? $dir : ".") || next;
| while (defined($file = readdir(DIR))) {
| $_ = "$dir/$file";
| $D{$file} .= "\0$dir" unless m#/\.\.?$# || !-f $_ || !-x _
| || (stat(_))[3] > 1 && $F{$file,(stat(_))[0,1]}++;
| }
| closedir(DIR);
| }
| grep(((($x = $D{$_}) =~ s/\0/ /g) > 1 && print "$_\t$x\n"), sort keys(%D));
| ===============================================================================
|
| Try getting that output format from a shell script... :-)
OK, here's the one I wrote sorta blind (after watching the Perl code
spin by without paying much detail). It prints:
e: /bin/e,/usr/bin/e /usr/ucb/e
mail: /bin/mail,/usr/bin/mail /usr/ucb/mail
on stock Sunos4.1. Note that the links are shown separated by commas.
I didn't try to get it down into as few lines as possible. I save
that for .signatures. :-)
I think this version is a lot clearer about what it does. But maybe
that's because *I* wrote it. :-)
##################################################
#!/usr/bin/perl
for $bin (split(/:/, $ENV{'PATH'})) {
opendir(D,$bin) || next;
for $base (readdir(D)) {
$_ = "$bin/$base";
next unless -x && -f _;
$exec{$base} .= "$_\0";
}
closedir(D);
}
for (sort keys %exec) {
@exec = split(/\0/,$exec{$_});
next unless @exec > 1;
undef %list;
for (@exec) {
($dev, $ino) = stat $_;
$list{"$dev $ino"} .= "$_\0";
}
@vals = sort values %list;
next unless @vals > 1;
print "$_:";
for (@vals) {
chop;
s/\0/,/g;
print " $_";
}
print "\n";
}
##################################################
Just another Perl hacker,
--
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III |
| merlyn at iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/
More information about the Alt.sources.d
mailing list