delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/05/16/23:55:03

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Thu, 16 May 2002 23:54:47 -0400 (EDT)
From: Mark Blackburn <marklist AT fangorn DOT ca>
To: cygwin AT cygwin DOT com
Subject: Re: bash question
In-Reply-To: <3CE4430D.5050503@Salira.com>
Message-ID: <Pine.LNX.3.96.1020516235124.18127C-100000@rivendell.fangorn.ca>
MIME-Version: 1.0

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 <<END
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


--
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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019