Wednesday, April 16, 2008

Things I Forget: Loop Variables Are Global, Persistent

In the shell, loop variables, like diamonds, are forever.

Even though I "just meant 'for this loop' ," the shell thinks I really wanted it. This lies in the large class of "things I always forget."
$ for i in {0..5}
     > do
     >  echo $i
     > done
     0
     1
     2
     3
     4
     5
     $ echo $i
     5

No comments: