[comp.unix.questions] perl find-scripts

merlyn@intelob.intel.com (Randal L. Schwartz @ Stonehenge) (05/03/89)

In article <1932@Portia.Stanford.EDU>, karish@forel (Chuck Karish) writes:
| In article <113700004@uxa.cso.uiuc.edu> gsg0384@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(" ",@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@intelob.intel.com> ...!uunet!tektronix!biin!merlyn         }
{ or try <merlyn@agora.hf.intel.com> after 30 May 1989               }
\=Cute quote: "Welcome to Oregon... home of the California Raisins!"=/