delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/12/26/10:21:37

Date: Sun, 26 Dec 1999 10:13:11 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: "Mark E." <snowball3 AT bigfoot DOT com>
cc: djgpp-workers AT delorie DOT com, François Pinard <pinard AT iro DOT umontreal DOT ca>
Subject: A problem with ported Bash and redirection
Message-ID: <Pine.SUN.3.91.991226101139.16110V-100000@is>
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019