"Simple" but non-portable == useless.
Chip Salzenberg
chip at tct.uucp
Thu Jan 31 07:18:11 AEST 1991
According to tchrist at convex.COM (Tom Christiansen):
>I think he was talking about my script, not Karl's.
He certainly was; sorry for the misunderstanding.
>Chip's \0 stuff is sure the right way to go if you're that concerned.
After I posted my script, I realized that _trailing_ \0 is easier to
deal with, since the simplest output format is "s/\0/\n/". But I went
back to the leading \0 when I changed my output format.
>I'm not sure how easy it is to discern files with \n's in them from
>separate entries in Chip's output.
A directory that ends in newline could go undetected. Obviously I
could octalize all the names before printing them, but that takes the
output loop from grep() to for(), upping the line count by three. :-)
>Here are 7 lines (although I only see 5 lines of code), and it does run
>pretty fast.
But you cheated by omitting closedir(DIR).
>Notice I don't count files linked together.
Ah, that feature is useful. But your implementation skips the useful
heuristic of checking st_nlinks.
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... :-)
--
Chip Salzenberg at Teltronics/TCT <chip at tct.uucp>, <uunet!pdn!tct!chip>
"I want to mention that my opinions whether real or not are MY opinions."
-- the inevitable William "Billy" Steinmetz
More information about the Alt.sources.d
mailing list