Skip to content
C.W.K.
Stream
Lesson 03 of 10 · published

Login vs Non-Login, Interactive vs Non-Interactive

~10 min · login-shell, interactive, non-interactive

Level 0Window Tourist
0 XP0/95 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Two orthogonal axes

Every shell has two flags:

  • Login or not — login shells are the first shell of a session: Terminal.app on open, ssh login, su -.
  • Interactive or not — interactive shells have a prompt; non-interactive shells run scripts.

That gives 2x2 = four shell types, each loading a different set of config files.

The matrix (zsh)

InteractiveNon-interactive
Login.zshenv → .zprofile → .zshrc → .zlogin.zshenv → .zprofile → .zlogin
Non-login.zshenv → .zshrc.zshenv only

Real-world cases

  • Open Terminal.app → login + interactive (full reload).
  • ssh user@host → login + interactive.
  • ssh user@host 'echo hi' → login + non-interactive.
  • Run ./script.sh from a session → non-login + non-interactive.
  • Type zsh inside an existing zsh → non-login + interactive.
  • cron / launchd jobs → non-login + non-interactive (.zshenv only).

Why this trips people up

You add a required value to ~/.zshrc and it works in your terminal. A scheduled job starts with a different environment and may not run zsh at all. Declare its interpreter, PATH, working directory, and required non-secret values in the job contract; obtain secrets through the job's credential boundary instead of moving them into another shell startup file.

Confirm at runtime

[[ -o login ]] && echo login. [[ -o interactive ]] && echo interactive. The flags are introspectable from inside the shell.

Scheduled jobs do not inherit an interactive shell

Cron and launchd start from their own environment and may not run zsh at all. Declare the interpreter, PATH, working directory, and required non-secret values in the job contract; keep secrets in a credential store with narrowly scoped access rather than startup files.

The caller predicts which files can be read

Start with the process creator: Terminal, an SSH server, a scheduler, or a shebang. Inspect the actual executable, arguments, and environment before deciding whether login or interactive startup rules apply.

Code

Detect what you're running in·zsh
[[ -o login ]]       && echo 'login'       || echo 'non-login'
[[ -o interactive ]] && echo 'interactive' || echo 'non-interactive'

External links

Exercise

From your interactive zsh, run [[ -o interactive ]] && echo yes. Then zsh -c '[[ -o interactive ]] && echo yes || echo no' — the inner shell is non-interactive. Then bash -l -c 'echo $0' to see a login bash.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.