write count to a global variable before you exit the loop

> -----Original Message-----
> From: Dan Ferris [SMTP:[EMAIL PROTECTED]]
> Sent: Friday, March 17, 2000 1:05 AM
> To:   [EMAIL PROTECTED]
> Subject:      [newbie] shell programming question
> 
> Hi-
> 
> I am attempting to write a shell program for a school class that
> uses finger to find users who have never logged on.  It is a
> Bourne shell program, nothing fancy.
> 
> Here is the code. It is pretty short:
> 
> #/bin/sh
> export count=0
> cat /etc/passwd | cut -d: -f1,5 | tr ":" " " | tr "," " " | 
> while read userid username
> do
>       if finger $userid | grep "Never logged in." 1> /dev/null
>       then
>               echo "$userid ( $username ) has never logged on."
>               count=`expr $count + 1`
>       fi
> done
> 
> This program works.  Only problem is that it is required to count
> the number of users who have not logged on.  The variable count
> is exported so that the loop can use it.  Of course the loop is
> executed inside a subshell, so getting the new value out of the
> loop is...well...not obvious.  
> 
> Can anyone tell me how to get the new value of the variable out
> of the subshell and back to the original shell???
> 
> TIA,
>       Dan
> 
> -- 
> Any programming language is at its best before it is implemented
> and used.

Reply via email to