Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 May 2010 18:25:44 -0700
From:      Evuraan <evuraan@gmail.com>
To:        Paul Hoffman <phoffman@proper.com>
Cc:        freebsd-questions@freebsd.org
Subject:   bash while read question
Message-ID:  <x2n6fbcd0711005051825mf0835e29jbf5daaab5111b336@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
I cant figure out why the variable in in loop2 does not hike to +1?
(its a friday, i am dazed, I admit. but this should not be a mystery!)
any help would be much appreciated.


$ cat loop1
#! /bin/bash

date > /tmp/somefile
b="1"
while read blah; do
let b=(b+1)
done  < /tmp/somefile
echo "variable is $b"

$ cat loop2
#! /bin/bash

date > /tmp/somefile
b="1"
cat /tmp/somefile | while read blah; do
let b=(b+1)
done
echo "variable is $b"


$ ./loop1
variable is 2

$ ./loop2
variable is 1



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?x2n6fbcd0711005051825mf0835e29jbf5daaab5111b336>