[Gloucs] shell script

Mick Brooks gloucs at mailman.lug.org.uk
Thu Dec 19 23:57:00 2002


On Thu, Dec 19, 2002 at 11:23:15PM +0000, Will Roe wrote:
> On Thu, Dec 19, 2002 at 11:03:34PM +0000 or thereabouts, Guy Edwards wrote:

> > I've got the following shell script I've cobbled together, it's not
> > working though.
> > 
> > I want to open and close a program a number of times (I've used ls as an
> > example here but it's a bigger program)
> > 
> > -----------------
> > 
> > #!/bin/bash
> > 
> > opens="0"			// set the value of opens to 0
> opens=0
> > 
> > echo "Starting run"
> > 
> > while ($opens < 5); do		// while opens is less than 5 do....
> while [ $opens -lt 5 ] ; do

Ugh! I don't know bash scripting, but was playing with Guy's code. I can't
believe that [$opens -lt 5] != [ $opens =lt 5 ] ! Thank Larry Wall for Perl.
I'd gotten used to whitespace not mattering...

> >         ls			// command name
> >         $$=$current		// store its process ID
> current=$$
> > 	sleep 10		// give program time to finish starting
> >         kill $current		// kill the process 

Doesn't $$ contain the PID of the script? You probably want to stick your
process in the background (as Will says) and use $!.

Have fun,

-- 
Mick Brooks
michael.brooks@physics.ox.ac.uk