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
> 
> 
> [hal@feenix hal]$ bash -version
> GNU bash, version 2.04.11(1)-release (i386-redhat-linux-gnu)
> Copyright 1999 Free Software Foundation, Inc.


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

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

(I renamed it to foo.bar)





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

Reply via email to