Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!unmvax!ncar!ames!lll-winken!uunet!littlei!omepd!merlyn From: merlyn@intelob.intel.com (Randal L. Schwartz @ Stonehenge) Newsgroups: comp.unix.questions Subject: perl find-scripts (was Re: Which shell language should I use?) Summary: code attached Message-ID: <4365@omepd.UUCP> Date: 2 May 89 19:27:31 GMT References: <113700004@uxa.cso.uiuc.edu> <1932@Portia.Stanford.EDU> Sender: news@omepd.UUCP Reply-To: merlyn@intelob.intel.com (Randal L. Schwartz @ Stonehenge) Organization: Stonehenge; netaccess via BiiN, Hillsboro, Oregon, USA Lines: 53 In-reply-to: karish@forel.stanford.edu (Chuck Karish) 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 = ) { chop($here); next unless -x $here && -T $here; open(F,$here) || next; $_ = ; 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 } { ...!uunet!tektronix!biin!merlyn } { or try after 30 May 1989 } \=Cute quote: "Welcome to Oregon... home of the California Raisins!"=/