[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bash: variables inside 'while'
From: |
Gabriel Zachmann |
Subject: |
bash: variables inside 'while' |
Date: |
30 Aug 2001 10:06:10 GMT |
User-agent: |
slrn/0.9.7.0 (Linux) |
Consider this:
xx=1
cat file |
while read p l
do
xx=$p
echo xx=$xx
break
done
echo xx=$xx
As output I get:
xx=grid
xx=1
(the first line of my 'file' contains the word grid).
ARGH! why is the variable 'xx' reset outside the 'while' loop???
With a simpler example:
xx=1; while true; do xx=2; echo xx=$xx; break; done; echo xx=$xx
everything is fine, and I get the output:
xx=2
xx=2
This happens with version 2.05.8(1) (under redhat 7.1).
what's even more surprising is that the first example (with the 'cat')
works fine on the bash under cygwin (I don't recall right now which version).
HTH,
Gab.
--
/---------------------------------------------------------------------\
| And what if all of animated nature |
| Be but organic Harps diversely fram'd, |
| That tremble into thought, as o'er them sweeps |
| Plastic and vast, one intellectual breeze, |
| At once the Soul of each, and God of all? (Samuel Taylor Coleridge)|
| |
| address@hidden __@/' address@hidden |
| web.informatik.uni-bonn.de/~zach __@/' www.gabrielzachmann.org |
\---------------------------------------------------------------------/
- bash: variables inside 'while',
Gabriel Zachmann <=