On Thu, 18 Jan 2001, Hal Burgiss wrote:
> On Thu, Jan 18, 2001 at 10:34:30PM -0500, Statux wrote:
> > This is correct behavior (from what I've known). The variables in the loop
> > are defined as temporary variables.. they have scope limited to the loop.
I don't think shells have a concept between local and global scope. The
issue is that the pipe creates a subshell, which inherits the first shell
environment, but doesn't pass it back when it exits ... here's an example
...
The first three tests all create subshells that modify $num. The fourth
doesn't, and there $num is modified for the script.
#!/bin/bash
echo "First test pipe to while"
num=0
echo 1 | while read line; do
num=1
echo $num
done
echo $num
echo "Second test while in subshell"
num=0
(
while [ $num -eq 0 ]; do
num=1
echo $num
done
)
echo $num
echo "Third test subshell without while"
num=0
(
num=1
echo $num
)
echo $num
echo "Fourth test while without subshell"
num=0
while [ $num -eq 0 ]; do
num=1
echo $num
done
echo $num
_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list