Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com From: "Bernard A Badger" To: "Mark Blackburn" , Subject: RE: bash question Date: Fri, 17 May 2002 10:01:26 -0400 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal In-Reply-To: Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 > -----Original Message----- > From: cygwin-owner AT cygwin DOT com [mailto:cygwin-owner AT cygwin DOT com]On Behalf > Of Mark Blackburn > Sent: Thursday, May 16, 2002 11:55 PM > To: cygwin AT cygwin DOT com > Subject: Re: bash question > > > You asked this in the wrong place btw, (I think its a bash specific > questing) but here goes anyways: > #!/bin/bash > > i=0 > for x in 1 2 3; do > let i=i+1 > echo "item $x" > done > > echo "Processed $i items" > > cat > /tmp/file < item 1 > item 2 > item 3 > END > > cat /tmp/file | { export i=0; while read item; do \ > let i=i+1 ; \ > echo "Read $item $i" ; \ > done } > > echo "Processed $i items" > > rm -f /tmp/file > > output is: > item 1 > item 2 > item 3 > Processed 3 items > Read item 1 1 > Read item 2 2 > Read item 3 3 > Processed 3 items > Sorry, wrong answer. You're just printing out the first count again. The second count is lost, but happens to be 3 also. Add couple of lines to the file to see: $ ./tscript.sh item 1 item 2 item 3 Processed 3 items Read item 1 1 Read item 2 2 Read item 3 3 Read item 4 4 Read item 5 5 Processed 3 items The following version works: #!/bin/bash i=0 for x in 1 2 3; do let i=i+1 echo "item $x" done echo "Processed $i items" i=0 cat > /tmp/file < > -- > Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple > Bug reporting: http://cygwin.com/bugs.html > Documentation: http://cygwin.com/docs.html > FAQ: http://cygwin.com/faq/ -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/