Bourne shell oddity
SILL D E
de5 at STC06.CTD.ORNL.GOV
Wed Aug 8 01:35:07 AEST 1990
What should the following script do?
#!/bin/sh
foo=bar
while true
do
if [ $foo = bar ]
then
foo=baz
echo foo=${foo}
break
fi
done </dev/null
echo foo=${foo}
I would have expected it to output:
foo=baz
foo=baz
But I get:
foo=baz
foo=bar
Removing the input redirection from the while-loop gives the expected
result.
Question: Is this a bug, or is I/O redirection of commands supposed
to affect variable scoping somehow? I couldn't find anything in the
FM to explain this behavior.
Another Question: Is there a simple workaround, preferably something
more elegant than passing values in files?
Please reply by mail; I don't follow this group/list.
Thanks.
--
Dave Sill (de5 at ornl.gov)
Martin Marietta Energy Systems
Workstation Support
More information about the Comp.unix.questions
mailing list