On Fri, Jan 19, 2001 at 10:36:47AM -0500, Jeff Lane wrote:
> On Thu, 18 Jan 2001, Hal Burgiss wrote:
> 
> > Is the below expected behavior? or bug? Values assigned to
> > variables within the loop, are not visible outside the loop. Using
> > something like 'while true' works as I would expect.
> > 
> > #!/bin/bash
> > ## script: testing
> > ## test variable visibility
> > 
> > num=0
> > echo 1 > tmp
> > 
> > cat tmp |while read line ; do 
> >  
> >  num=1
> >  echo $num
> > 
> > done
> > 
> > echo $num
> > 
> > #--- eof testing
> > 
> > [hal@feenix hal]$ testing
> > 1
> > 0
> 
> I would imagine that this is because num is resetting to 0.  in the
> while loop you set num = 1 then echo $num...  then after done, I
> would imagine that num is being reset to its original value...  

Yea, obviously either being set to original value OR, the changes in
the loop just aren't visible outside the loop. Six of one ...
 
> just a guess...  
> 
> All you did was reinitialize the variable.  if you comment out the num=0
> line, you get this:
> 
> [10:32:59][jlane@§î£èñßøß]$ ./foo.bar 
> 1
> 

Very interesting behavior. At least to me. I would not have expected
that. Food for thought...thanks.

-- 
Hal B
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
--



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to