Mail Archives: djgpp-workers/1999/12/26/10:21:37
Consider the following simple shell script:
echo foo
echo bar
echo baz
Now let us run the ported Bash 2.03 thusly:
sh < script
You will see what you expect:
foo
bar
baz
Now modify the script like this:
echo foo < /dev/null
echo bar
echo baz
and run it again. Surprise! what we see is just one line:
foo
Try moving the redirection from line to line, and you will see the
trend: the first line which redirects stdin to the null device is the
*last* line that is ever executed in that script; the rest are
ignored.
This looks like a bug in the ported Bash. Mark, I'm guessing that
Bash redirects its stdin before invoking each command, but doesn't
restore the old stdin after the command returns. So it hits EOF right
after the first redirection, and exits.
- Raw text -