perl find-scripts (was Re: Which shell language should I use?)
Randal L. Schwartz @ Stonehenge
merlyn at intelob.intel.com
Wed May 3 05:27:31 AEST 1989
In article <1932 at Portia.Stanford.EDU>, karish at forel (Chuck Karish) writes:
| In article <113700004 at uxa.cso.uiuc.edu> gsg0384 at uxa.cso.uiuc.edu wrote:
| >1. How much of the Berkeley-originated script files were written
| >in Bourn-shell language?
|
| A good exercise for the original poster. Write a script
| to look for csh syntax/magic cookies in all the scripts
| on your machine. I'd use `find', `file', and `sed' to
| do it.
Done, in perl. (I did this about a month ago.)
================================================== snip snip
#!/usr/bin/perl
## find-scripts: find all the exec-able scripts in a directory hierarchy
## usage: $0 [directories...]
## if no directory, defaults to $HOME
$| = 1; # don't buffer stdout
if ($#ARGV < 0) {
@ARGV = ($ENV{"HOME"} || die);
}
open(FIND,"find " . join(" ", at ARGV) . " -print|") ||
die "Cannot open find ($!)\n";
while ($here = <FIND>) {
chop($here);
next unless -x $here && -T $here;
open(F,$here) || next;
$_ = <F>;
close(F);
if (/^#!\s*(\S+)/) {
$f = $1;
} elsif (/^#/) {
$f = "(/bin/csh)";
} else {
$f = "(/bin/sh)";
}
print "$here: $f\n";
}
close(FIND);
================================================== snip snip
Just another Perl hacker (thanks, Larry)...
--
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095===\
{ on contract to BiiN, Hillsboro, Oregon, USA, until 30 May 1989 }
{ <merlyn at intelob.intel.com> ...!uunet!tektronix!biin!merlyn }
{ or try <merlyn at agora.hf.intel.com> after 30 May 1989 }
\=Cute quote: "Welcome to Oregon... home of the California Raisins!"=/
More information about the Comp.unix.questions
mailing list