On Mon, 17 Apr 2006 01:35:57 +0200, Ken Dyke wrote: > Simple problem I am not getting. Please apply cluebat. > > I have an accumulator variable inside a while loop. I want access to > the contents after the while loop completes but am getting a null value. > > Thanks, > > #!/bin/bash > # > # to test make file foo with single line in same directory as test > # script > > cat foo | while read line ; do > let error_code=$error_code+1 > echo "error_code inside while loop $error_code" > done > > echo "error_code outside while loop $error_code" > # end test script
You are using the while loop inside a pipe. The $error_code variable does not continue to exist outside the pipe. Have a look at this: [EMAIL PROTECTED]:~ $ echo $foo [EMAIL PROTECTED]:~ $ echo hello | foo=bar [EMAIL PROTECTED]:~ $ echo $foo [EMAIL PROTECTED]:~ $ foo=bar [EMAIL PROTECTED]:~ $ echo $foo bar In /etc/rc.d/init.d/cleanfs another method is used to read the contents of a file; perhaps you can use that: exec 9>&0 < /etc/sysconfig/createfiles while read name type perm usr grp dtype maj min junk do Tim -- http://linuxfromscratch.org/mailman/listinfo/lfs-chat FAQ: http://www.linuxfromscratch.org/faq/ Unsubscribe: See the above information page
