* 'login' vs 'interactive' ? @ 2014-11-18 16:11 TJ Luoma 2014-11-18 16:21 ` Axel Beckert 2014-11-18 16:39 ` Peter Stephenson 0 siblings, 2 replies; 7+ messages in thread From: TJ Luoma @ 2014-11-18 16:11 UTC (permalink / raw) To: Zsh-Users List 1) Can someone explain the difference between 'login' and 'interactive' in these two examples: if [[ -o login ]]; then echo "I'm a login shell" fi if [[ -o interactive ]]; then echo "I'm interactive" fi 2) is 'login' vs 'interactive' similar to "every square is a rectangle but a rectangle is not necessarily a square"? As in "Every login shell is interactive, but an interactive shell is not necessarily a login shell"? 3) Imagine an alternate universe where zsh _automatically_ reads ~/.zshenv but NOT ~/.zshrc so you had to tell zsh to read ~/.zshrc as part of ~/.zshenv. Would the answer be: if [[ -o login ]]; then source .zshrc fi or if [[ -o interactive ]]; then source .zshrc fi or does it matter? 4) Anything else I should understand about these two? Thanks! TjL ps - I swear I knew the answer to this at one time, but I can't remember it, nor has Google helped me find the answer. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'login' vs 'interactive' ? 2014-11-18 16:11 'login' vs 'interactive' ? TJ Luoma @ 2014-11-18 16:21 ` Axel Beckert 2014-11-18 17:19 ` Ray Andrews 2014-11-18 16:39 ` Peter Stephenson 1 sibling, 1 reply; 7+ messages in thread From: Axel Beckert @ 2014-11-18 16:21 UTC (permalink / raw) To: zsh-users Hi, On Tue, Nov 18, 2014 at 11:11:46AM -0500, TJ Luoma wrote: > 2) is 'login' vs 'interactive' similar to "every square is a rectangle > but a rectangle is not necessarily a square"? Nope. It's more like rectangle and rhombus. A shape can be one of them, none of them or both. It's more like 2x2 matrix. See http://tanguy.ortolo.eu/blog/article25/shrc for an in my humble opinion nice explanation and visualization. Kind regards, Axel -- /~\ Plain Text Ribbon Campaign | Axel Beckert \ / Say No to HTML in E-Mail and News | abe@deuxchevaux.org (Mail) X See http://www.nonhtmlmail.org/campaign.html | abe@noone.org (Mail+Jabber) / \ I love long mails: http://email.is-not-s.ms/ | http://noone.org/abe/ (Web) ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'login' vs 'interactive' ? 2014-11-18 16:21 ` Axel Beckert @ 2014-11-18 17:19 ` Ray Andrews 2014-11-18 19:27 ` Axel Beckert 0 siblings, 1 reply; 7+ messages in thread From: Ray Andrews @ 2014-11-18 17:19 UTC (permalink / raw) To: zsh-users On 11/18/2014 08:21 AM, Axel Beckert wrote: > > 2) is 'login' vs 'interactive' similar to "every square is a rectangle > but a rectangle is not necessarily a square"? > Nope. It's more like rectangle and rhombus. A shape can be one of > them, none of them or both. It's more like 2x2 matrix. > > See http://tanguy.ortolo.eu/blog/article25/shrc for an in my humble > opinion nice explanation and visualization. Nicely written, but why not show the intersections of all possible 'types'? I take it there's interactive, non-interactive and login. Any others? > Kind regards, Axel ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'login' vs 'interactive' ? 2014-11-18 17:19 ` Ray Andrews @ 2014-11-18 19:27 ` Axel Beckert 0 siblings, 0 replies; 7+ messages in thread From: Axel Beckert @ 2014-11-18 19:27 UTC (permalink / raw) To: zsh-users Hi, On Tue, Nov 18, 2014 at 09:19:49AM -0800, Ray Andrews wrote: > > See http://tanguy.ortolo.eu/blog/article25/shrc for an in my humble > > opinion nice explanation and visualization. > > Nicely written, but why not show the intersections of all possible > 'types'? I take it there's interactive, non-interactive and login. "interactive" and "non-interactive" are the same type, just either "yes" or "no" -- like "login" and "non-login" would be "yes" and "no" for the type "login". Kind regards, Axel -- /~\ Plain Text Ribbon Campaign | Axel Beckert \ / Say No to HTML in E-Mail and News | abe@deuxchevaux.org (Mail) X See http://www.nonhtmlmail.org/campaign.html | abe@noone.org (Mail+Jabber) / \ I love long mails: http://email.is-not-s.ms/ | http://noone.org/abe/ (Web) ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'login' vs 'interactive' ? 2014-11-18 16:11 'login' vs 'interactive' ? TJ Luoma 2014-11-18 16:21 ` Axel Beckert @ 2014-11-18 16:39 ` Peter Stephenson 2014-11-18 16:57 ` René Neumann 1 sibling, 1 reply; 7+ messages in thread From: Peter Stephenson @ 2014-11-18 16:39 UTC (permalink / raw) To: Zsh-Users List On Tue, 18 Nov 2014 11:11:46 -0500 TJ Luoma <luomat@gmail.com> wrote: > 1) Can someone explain the difference between 'login' and > 'interactive' in these two examples: > > if [[ -o login ]]; then > echo "I'm a login shell" > fi > > if [[ -o interactive ]]; then > echo "I'm interactive" > fi Overall, the differences are two-fold (i) how you got there (ii) what the consequences are. You might like to read zsh.sourceforge.net/Guide/zshguide02.html which I wrote some years ago but makes attempts in the right direction. How you got there --- what makeas a shell a login shell --- is described on page 108 of "From Bash to Z Shell". Basically, it's done by executive decision of whatever it is that's starting your shell. That's not very easy to summarise nowadays when there are so many ways of starting the shell. What makes a shell interactive is very roughly that the shell itself thought it had an environment that looked like a terminal and couldn't think of any reason why the user might not want it to use that terminal (e.g. being passed a script is such a reason). What the consequences are has got a lot to do with startup files, so I've appended the bit from the FAQ (this is pretty much the only use of being a login shell, apart from an explicit test like the one you've got above). However, the shell bases a number of internal decisions on whether or not it's interactive. These are intended to be common sense, e.g. if it's interactive you want the line editor and if it's not interactive you don't. Needless to say, it's not always that simple. > 2) is 'login' vs 'interactive' similar to "every square is a rectangle > but a rectangle is not necessarily a square"? > > As in "Every login shell is interactive, but an interactive shell is > not necessarily a login shell"? Not necessarily, in fact, because neither of the two points above is a subset of the other. For example, something managing the way your window system starts may decide to launch the shell that sets up the environment as a login shell, but without a terminal. > 3) Imagine an alternate universe where zsh _automatically_ reads > ~/.zshenv but NOT ~/.zshrc so you had to tell zsh to read ~/.zshrc as > part of ~/.zshenv. > > Would the answer be: > > if [[ -o login ]]; then > source .zshrc > fi > > or > > if [[ -o interactive ]]; then > source .zshrc > fi The second. This actually is well-defined and even documented. See below. > 4) Anything else I should understand about these two? Your counterfactual ~/.zshenv would also contain (being somewhat more, but not necessarily completely, pedantic about associated tests): if [[ -o login && -f ${ZDOTDIR:-$HOME}/.zlogin ]]; then source ${ZDOTDIR:-$HOME}/.zlogin fi and there's likewise pseudo-code for .zlogout (but nowhere to put it other than an EXIT trap). FAQ excerpt follows. 3.2: In which startup file do I put...? When zsh starts up, there are four files you can change which it will run under various circumstances: .zshenv, .zprofile, .zshrc and .zlogin. They are usually in your home directory, but the variable $ZDOTDIR may be set to alter that. Here are a few simple hints about how to use them. There are also files which the system administrator can set for all shells; you can avoid running all except /etc/zshenv by starting zsh with the -f option --- for this reason it is important for administrators to make sure /etc/zshenv is as brief as possible. The order in which the four files are searched (none of them _need_ to exist) is the one just given. However, .zprofile and .zlogin are only run when the shell is a login shell --- when you first login, of course, and whenever you start zsh with the -l option. All login shells are interactive. The order is the only difference between those; you should decide whether you need things set before or after .zshrc. These files are a good place to set environment variables (i.e. `export' commands), since they are passed on to all shells without you having to set them again, and also to check that your terminal is set up properly (except that if you want to change settings for terminal emulator windows like xterm you will need to put those in .zshrc, since usually you do not get a login shell here). The only file you can alter which is started with every zsh (unless you use the -f option) is .zshenv, so this is a good place to put things you want even if the shell is non-interactive: options for changing the syntax, like EXTENDED_GLOB, any changes to set with `limit', any more variables you want to make sure are set as for example $fpath to find functions. You almost certainly do not want .zshenv to produce any output. Some people prefer not to use .zshenv for setting options, as this affects scripts; but making zsh scripts portable usually requires special handling anyway. Finally, .zshrc is run for every interactive shell; that includes login shells, but also any other time you start up a shell, such as simply by typing `zsh' or opening a new terminal emulator window. This file is the place to change the editing behaviour via options or `bindkey', control how your history is saved, set aliases unless you want to use them in scripts too, and for any other clutter which can't be exported but you only use when interacting directly with the shell. You probably don't want .zshrc to produce output, either, since there are occasions when this can be a problem, such as when using `rsh' from another host. See 3.21 for what to put in .zshrc to save your history. pws ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'login' vs 'interactive' ? 2014-11-18 16:39 ` Peter Stephenson @ 2014-11-18 16:57 ` René Neumann 2014-11-18 17:06 ` Peter Stephenson 0 siblings, 1 reply; 7+ messages in thread From: René Neumann @ 2014-11-18 16:57 UTC (permalink / raw) To: zsh-users Just noted a small flaw in the FAQ: Am 18.11.2014 um 17:39 schrieb Peter Stephenson: > >> 2) is 'login' vs 'interactive' similar to "every square is a rectangle >> but a rectangle is not necessarily a square"? >> >> As in "Every login shell is interactive, but an interactive shell is >> not necessarily a login shell"? > > Not necessarily, in fact, because neither of the two points above is a > subset of the other. For example, something managing the way your > window system starts may decide to launch the shell that sets up the > environment as a login shell, but without a terminal. vs (from the FAQ-excerpt you quoted) > All login shells are interactive. - René ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'login' vs 'interactive' ? 2014-11-18 16:57 ` René Neumann @ 2014-11-18 17:06 ` Peter Stephenson 0 siblings, 0 replies; 7+ messages in thread From: Peter Stephenson @ 2014-11-18 17:06 UTC (permalink / raw) To: zsh-users On Tue, 18 Nov 2014 17:57:09 +0100 René Neumann <lists@necoro.eu> wrote: > vs (from the FAQ-excerpt you quoted) > > > All login shells are interactive. That's even older than the other sources of information... diff --git a/Etc/FAQ.yo b/Etc/FAQ.yo index 08ea979..dcb2ec5 100644 --- a/Etc/FAQ.yo +++ b/Etc/FAQ.yo @@ -1017,19 +1017,26 @@ sect(In which startup file do I put...?) reason it is important for administrators to make sure tt(/etc/zshenv) is as brief as possible. - The order in which the four files are searched (none of them myem(need) - to exist) is the one just given. However, tt(.zprofile) and tt(.zlogin) - are only run when the shell is a login shell --- when you first login, - of course, and whenever you start zsh with the tt(-l) option. All - login shells are interactive. The order is the only difference - between those; you should decide whether you need things set before or - after tt(.zshrc). These files are a good place to set environment - variables (i.e. mytt(export) commands), since they are passed on to - all shells without you having to set them again, and also to check - that your terminal is set up properly (except that if you want to - change settings for terminal emulator windows like tt(xterm) you will - need to put those in tt(.zshrc), since usually you do not get a login - shell here). + The order in which the four files are searched (none of them + myem(need) to exist) is the one just given. However, tt(.zprofile) + and tt(.zlogin) are only run when the shell is a login shell --- when + you first login, of course, and whenever you start zsh with the tt(-l) + option. The order is the only difference between those; you should + decide whether you need things set before or after tt(.zshrc). These + files are a good place to set environment variables (i.e. mytt(export) + commands), since they are passed on to all shells without you having + to set them again, and also to check that your terminal is set up + properly (except that if you want to change settings for terminal + emulator windows like tt(xterm) you will need to put those in + tt(.zshrc), since usually you do not get a login shell here). + + Login shells are often interactive, but this is not necessarily the + case. It is the programme that starts the shell that decides if it is + to be a login shell, and it is not required that the shell be run + interactively. A possible example is a display manager that starts a + shell to initialise your environment before running the window manager + to create terminals: it might run this as a login shell but with no + terminal, so it is not interactive. The only file you can alter which is started with every zsh (unless you use the tt(-f) option) is tt(.zshenv), so this is a good place to \ pws ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-11-18 19:28 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-11-18 16:11 'login' vs 'interactive' ? TJ Luoma 2014-11-18 16:21 ` Axel Beckert 2014-11-18 17:19 ` Ray Andrews 2014-11-18 19:27 ` Axel Beckert 2014-11-18 16:39 ` Peter Stephenson 2014-11-18 16:57 ` René Neumann 2014-11-18 17:06 ` Peter Stephenson
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).