zsh-users
 help / color / mirror / code / Atom feed
* [[ -o interactive ]] vs if [[ -o login ]]?
@ 2011-08-14 22:46 TJ Luoma
  2011-08-14 23:24 ` Mikael Magnusson
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: TJ Luoma @ 2011-08-14 22:46 UTC (permalink / raw)
  To: Zsh Users

If there any reason to prefer

if [[ -o interactive ]]

rather than

 if [[ -o login ]]

?

Are they two ways of saying the same thing? If not, could someone
explain the difference?

Thanks

TjL


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [[ -o interactive ]] vs if [[ -o login ]]?
  2011-08-14 22:46 [[ -o interactive ]] vs if [[ -o login ]]? TJ Luoma
@ 2011-08-14 23:24 ` Mikael Magnusson
  2011-08-14 23:25 ` Michael Shick
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Mikael Magnusson @ 2011-08-14 23:24 UTC (permalink / raw)
  To: TJ Luoma; +Cc: Zsh Users

On 15 August 2011 00:46, TJ Luoma <luomat@gmail.com> wrote:
> If there any reason to prefer
>
> if [[ -o interactive ]]
>
> rather than
>
>  if [[ -o login ]]
>
> ?
>
> Are they two ways of saying the same thing? If not, could someone
> explain the difference?

login is only set for login shells, interactive is set for all
interactive shells. I suspect that doesn't help you a lot though since
that part's pretty obvious ;). A login shell is something that is
started at the beginning of some sort of session, like logging in to X
or the console, and it will be started like $SHELL -l or -$SHELL (with
a - prepended to argv[0]). Any time you just open a terminal or run
"zsh" it is likely not a login shell, unless you configure your
terminal emulator to always start a login shell.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [[ -o interactive ]] vs if [[ -o login ]]?
  2011-08-14 22:46 [[ -o interactive ]] vs if [[ -o login ]]? TJ Luoma
  2011-08-14 23:24 ` Mikael Magnusson
@ 2011-08-14 23:25 ` Michael Shick
  2011-08-14 23:28 ` Vincent Lefevre
  2011-08-15  0:12 ` Bart Schaefer
  3 siblings, 0 replies; 7+ messages in thread
From: Michael Shick @ 2011-08-14 23:25 UTC (permalink / raw)
  To: TJ Luoma; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 540 bytes --]

An interactive shell is just that; it reads and writes to and from a
terminal (ideally one with a user at it).  A login shell reads and runs
login-related files like /etc/profile and ~/.profile.  An interactive shell
need not be a login shell and vice versa.
On Aug 14, 2011 6:57 PM, "TJ Luoma" <luomat@gmail.com> wrote:
> If there any reason to prefer
>
> if [[ -o interactive ]]
>
> rather than
>
> if [[ -o login ]]
>
> ?
>
> Are they two ways of saying the same thing? If not, could someone
> explain the difference?
>
> Thanks
>
> TjL

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [[ -o interactive ]] vs if [[ -o login ]]?
  2011-08-14 22:46 [[ -o interactive ]] vs if [[ -o login ]]? TJ Luoma
  2011-08-14 23:24 ` Mikael Magnusson
  2011-08-14 23:25 ` Michael Shick
@ 2011-08-14 23:28 ` Vincent Lefevre
  2011-08-14 23:44   ` TJ Luoma
  2011-08-15  0:12 ` Bart Schaefer
  3 siblings, 1 reply; 7+ messages in thread
From: Vincent Lefevre @ 2011-08-14 23:28 UTC (permalink / raw)
  To: zsh-users

On 2011-08-14 18:46:53 -0400, TJ Luoma wrote:
> If there any reason to prefer
> 
> if [[ -o interactive ]]
> 
> rather than
> 
>  if [[ -o login ]]
> 
> ?
> 
> Are they two ways of saying the same thing? If not, could someone
> explain the difference?

Not all interactive shells are login shells. Typically, when one opens
a terminal, one just gets an interactive shell (though this can be
configurable).

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [[ -o interactive ]] vs if [[ -o login ]]?
  2011-08-14 23:28 ` Vincent Lefevre
@ 2011-08-14 23:44   ` TJ Luoma
  0 siblings, 0 replies; 7+ messages in thread
From: TJ Luoma @ 2011-08-14 23:44 UTC (permalink / raw)
  To: zsh-users

Thanks, all… I guess I only launch zsh two ways:

1) a login shell (changing my $SHELL to zsh is one of the first things I do)

2) a #!/path/to/zsh shell script

So I guess I never thought about launching zsh from another shell. It
would be handy if you couldn't change your $SHELL I suppose…

TjL


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [[ -o interactive ]] vs if [[ -o login ]]?
  2011-08-14 22:46 [[ -o interactive ]] vs if [[ -o login ]]? TJ Luoma
                   ` (2 preceding siblings ...)
  2011-08-14 23:28 ` Vincent Lefevre
@ 2011-08-15  0:12 ` Bart Schaefer
  2011-08-15  1:28   ` Vincent Lefevre
  3 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2011-08-15  0:12 UTC (permalink / raw)
  To: Zsh Users

On Aug 14,  6:46pm, TJ Luoma wrote:
}
} if [[ -o interactive ]]
} if [[ -o login ]]
} 
} Are they two ways of saying the same thing? If not, could someone
} explain the difference?

Unless someone is playing games with the command-line switches when
starting zsh: 

[[ -o interactive ]] is always true when [[ -o login ]] is true.

But

[[ -o login ]] is NOT always true when [[ -o interactive ]] is true.

(That is, you can forcibly "zsh -o nointeractive -o login" but that
will never happen in ordinary usage.)

As far as the shell itself is concerned, the only difference is in
whether the ~/.zlogin and ~/.zlogout files are read at startup and
normal exit, respectively.  (And their /etc/ counterparts, too.)

At a larger level, it's usually the case that login shells are those
started directly by the OS when a user logs in on a terminal, whereas
interactive shells are those started indirectly from a login shell.
The advent of windowing systems, however, often means that there is
no single login shell and it's up to the configuration of the terminal
emulator whether a shell started in a window behaves as a login shell.

The intent is that certain environment setup can be done once when the
user first logs in, and then not done again.  Under a windowing system,
the session manager is usually responsible for that one-time setup, but
for remote shells it may still be useful to have the shell do it.

Typically login shells have an entry in the utmp database (the output
of the "who" command) and other shells do not, but again that's up to
the process that started the shell, not the shell itself.

-- 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [[ -o interactive ]] vs if [[ -o login ]]?
  2011-08-15  0:12 ` Bart Schaefer
@ 2011-08-15  1:28   ` Vincent Lefevre
  0 siblings, 0 replies; 7+ messages in thread
From: Vincent Lefevre @ 2011-08-15  1:28 UTC (permalink / raw)
  To: zsh-users

On 2011-08-14 17:12:48 -0700, Bart Schaefer wrote:
> The intent is that certain environment setup can be done once when the
> user first logs in, and then not done again.  Under a windowing system,
> the session manager is usually responsible for that one-time setup, but
> for remote shells it may still be useful to have the shell do it.

But since non-interactive shells aren't normally login shells, one may
need to set up the environment directly from the .zshenv file. This is
useful when running commands via ssh:

  ssh host some_command_started_by_zsh

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-08-15  1:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-14 22:46 [[ -o interactive ]] vs if [[ -o login ]]? TJ Luoma
2011-08-14 23:24 ` Mikael Magnusson
2011-08-14 23:25 ` Michael Shick
2011-08-14 23:28 ` Vincent Lefevre
2011-08-14 23:44   ` TJ Luoma
2011-08-15  0:12 ` Bart Schaefer
2011-08-15  1:28   ` Vincent Lefevre

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).