This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]