[lug] In But Not Out Of Loop

Kenneth D. Weinert kenweinert at home.com
Sun May 27 09:48:29 MDT 2001


Do you mean like this?

ls *.c | while read $file; do
C = $[$C + $(wc -c $file)]
done

echo $C


if you pipe something through a while loop that happens in a subshell.

I've been bit by that before.

At 04:40 AM 5/27/01 -0600, you wrote:

>This seems to work for me:
>
>C=0;
>while [ $C -lt 100 ] ; do
>         echo $C;
>         C=$[$C+1];
>done;
>echo "C is $C"
>
>Do you have a specific example?
>
>Regards,
>
>Eric Kilfoil
>Sr. UNIX Systems Engineer
>ViaWest Internet Services
>
>
>On Sun, 27 May 2001, SoloCDM wrote:
>
> > Every time I have a bash while, for or any other type of loop,
> > with numbers processed and saved to a variable, the numbers are
> > not in the variable outside the loop.  Although, the numbers are
> > capable of use and manipulation in the variable, for reassigning
> > the variable or recall, anytime before the loop ends.  How can the
> > variable's content be available outside the loop?
> >
> > Note: When you reply to this message, please include the mailing
> >       list/newsgroup address and my email address in To:.
> >
> > *********************************************************************
> > Signed,
> > SoloCDM
> > _______________________________________________
> > Web Page:  http://lug.boulder.co.us
> > Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> >
>
>_______________________________________________
>Web Page:  http://lug.boulder.co.us
>Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug




More information about the LUG mailing list