zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-users@zsh.org
Subject: Re: exec - interactive vs non-interactive shell
Date: Wed, 1 Jun 2011 21:42:40 +0100	[thread overview]
Message-ID: <20110601214240.6fde31de@pws-pc.ntlworld.com> (raw)
In-Reply-To: <4DE69918.4040205@gmail.com>

On Wed, 01 Jun 2011 21:55:04 +0200
"Radoulov, Dimitre" <cichomitiko@gmail.com> 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@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  reply	other threads:[~2011-06-01 20:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-01 19:55 Fwd: " Radoulov, Dimitre
2011-06-01 20:42 ` Peter Stephenson [this message]
2011-06-01 22:03   ` Radoulov, Dimitre
2011-06-02  8:59     ` Peter Stephenson
2011-06-02  9:37       ` Radoulov, Dimitre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110601214240.6fde31de@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).