Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: exec - interactive vs non-interactive shell



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.

> zsh-4.3.11[t]% zsh -i<  a_script
> zsh-4.3.11[t]%
> 
> 
> No output with -i.

You're confusing the effects of "zsh -i <a_script" with "zsh -i
a_script".  The first one starts up zsh as an interactive shell, with a
line editor, but with standard input (not commands, which are
interactive) coming from a_script.  You'll find that prompt on the line
after is inside the new interactive shell.  Try typing at this point:

read
print $REPLY

You should see "exec ok".

The rules for how zsh finds the commands and standard input are roughly:

- Standard input is only redirected if you explicitly use a "<".
(So "zsh a_script" leaves stdin where it is and cat hangs waiting for
input.)  It's independent of interaction with the terminal for reading
commands (though there's the more complicated issue of how the terminal
gets set up in the first place).

- If there's a script name, use that for commands, regardless of whether
the shell is interactive or not.  (So "zsh -i a_script" behaves
basically like without the -i, although you could have interactive shell
commands such as vared in the script.)

- If there's no script name and the shell is interactive, use the
terminal for commands.

- If there's no script name and the shell is not interactive, fall back
to reading commands from standard input.  This is the only case (without
making special arrangements) where commands and standard input come from
the same channel.

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



Messages sorted by: Reverse Date, Date, Thread, Author