Why is ~/.zprofile always sourced on every interactive session?
from zsh document, ~/.zprofile
should only be sourced at login shell, and should NOT be sourced at every interactive session (for example, a new tab in a terminal).
- I am running MacOS Big Sur 11.2.3 (20D91).
But I can confirm that my ~/.zprofile
is sourced at every interactive session (a new tab). Why is that? Is this a bug? How to stop this incorrect behavior?
Solution 1:
Each Terminal tab is a login session on macOS by default. You can run w
to see that each tab/tty running a shell has a process name starting with -
attached to it (which indicates a login shell).
Additional information (related to bash
, but the same is applicable to other shells)
- What options does Terminal pass to bash on startup?
- Why doesn't .bashrc run automatically? (some of the answers explain details)
- What are the differences between /usr/bin/login and /usr/bin/bash?
- Why doesn't Mac OS X source ~/.bashrc?
PS: If I remember correctly we have a Q&A which goes into even more detail on this including a rationale why macOS considers each Terminal window/tab to be a login shell. I didn't find it yet though...