this post was submitted on 18 Jul 2024
272 points (98.6% liked)
Programmer Humor
19688 readers
105 users here now
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I found this diagram on SO at one point but I can’t find the post and it is the best explanation I have found for how all of the files work for bash and zsh, each color is an individual path of execution (eg, follow the red line).
Bottom line though, it only really matters if you are overriding something that is already defined, for example I tell my users to use zshrc and I provide defaults and common things in zprofile because zshrc is executed last when they login.
What do the differently coloured arrows mean? I'm confused.
Select the color which matches the steps before filenames ((non-)login and (non-)interactive), then follow that arrow the rest of the way. There's more colors in Bash because Bash makes a distinction between remote and local shells.
Another way to look at the same data for Zsh (note:
$ZDOTDIR
will be used instead of$HOME
if it's defined at any step along the way):/etc/zshenv
${ZDOTDIR:-$HOME}/.zshenv
${ZDOTDIR:-$HOME}/.zprofile
${ZDOTDIR:-$HOME}/.zshrc
${ZDOTDIR:-$HOME}/.zlogin
${ZDOTDIR:-$HOME}/.zlogout
One confusion on the Bash side of the diagram is that you see branching paths into
~/.profile
,~/.bash_profile
and~/.bash_login
. Bash will use for~/.bash_profile
,~/.bash_login
, and~/.profile
, in that order, and execute only the first one that exists and is readable.And what's confusing is that many times those files still manually call the others to make it more logical like zsh. That's what I remember at least, it's been quite a while since I used bash.
Yeah, most distros will set up
source
chains to make things nicer for users.