[Gllug] Bizarre shell behaviour

Pete Ryland pdr at accucard.com
Mon Nov 10 12:17:13 UTC 2003


On Sat, Nov 08, 2003 at 02:17:59AM +0000, Dylan wrote:
> On Friday 07 November 2003 23:57 pm, Bruce Richardson wrote:
> > On Fri, Nov 07, 2003 at 11:27:51PM +0000, Dylan wrote:
> > > On Friday 07 November 2003 17:16 pm, Tethys wrote:
> > > > Take the following shell script. Run it:
> > > >
> > > > 	#!/bin/sh
> > > >
> > > > 	count=0
> > > > 	while read var
> > > > 	do
> > > > 		count=1
> > > > 	done < /etc/group
> > > >
> > > > 	echo $count
> > >
> > > Just out of interest (and 'cos I'm trying to learn shell scripting) can
> > > someone explain what this is supposed to achieve. The loop is obvious,
> > > but what's the redirection all about?
> >
> > It's reading from the file /etc/group, one line at a time.
> 
> Thanks. I added an echo $var before the done and got a listing of the file so 
> I figure each line is going into $var. How does this work then?

I'd expect this is only the buggy part of a longer script, reduced to
emphasise the "feature".  The original script probably did some processing
for each line read.  The expected value of count was 1 if there was one or
more lines read, or 0 if the file was 0-byte.

Pete

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list