On Wed, 01 Jun 2011 23:03:23 +0100, Radoulov, Dimitre
<cichomitiko@xxxxxxxxx> wrote:
On 01/06/2011 22:42, Peter Stephenson wrote:
On Wed, 01 Jun 2011 21:55:04 +0200
"Radoulov, Dimitre"<cichomitiko@xxxxxxxxx> wrote:
zsh-4.3.11[t]% cat a_script
exec cat
ok
zsh-4.3.11[t]%
zsh-4.3.11[t]% zsh< a_script
ok
So cat has taken over stdin, as expected.
ash, dash and bash, for example, behave differently (ksh and variants
seem to behave like zsh).
Do you know if this behavior is defined by the POSIX standard?
I suppose this is down to the behaviour of exec. I didn't see anything
in the standard about what it should do with stdin when the current
shell was replaced with no additional redirection.
I think what's happened is probably that the shells that don't show
you anything have read ahead, so you still keep stdin from the same
place, but you don't necessarily get the very next line. I suspect
this behaviour isn't defined. (If that's right, then zsh's and ksh's
behaviour is the philosophically correct one, but there are
extenuating circumstances for the others.)
If the shell is interactive, there's no script name nor explicit
input redirection (<) ,
command and standard input come from the same channel too (the
terminal),
or I'm missing something?
You're not fundamentally missing anything, no, I deliberately glossed
over the way the shell opens the terminal. It is based on stdin,
but in practice the shell duplicates the file descriptor and does
its terminal processing on a hidden one (i.e. greater than 9).