this post was submitted on 18 Jul 2024
268 points (98.6% liked)

Programmer Humor

19512 readers
324 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

founded 1 year ago
MODERATORS
268
Which one??? (programming.dev)
submitted 3 months ago* (last edited 3 months ago) by JackbyDev@programming.dev to c/programmer_humor@programming.dev
 

Fuck it, .zshrc it is.

Image transcription:

  • Top text: I STILL DON'T KNOW WHAT SHOULD GO IN .*RC VERSUS .*PROFILE
  • Bottom text: AND AT THIS POINT I'M AFRAID TO ASK
you are viewing a single comment's thread
view the rest of the comments
[–] bigredgiraffe@lemmy.world 72 points 3 months ago (4 children)

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.

[–] JackbyDev@programming.dev 49 points 3 months ago (2 children)

I feel like I couldn't make this more confusing if I tried. What is doing on with the golden arrows around /etc/profile??

[–] agressivelyPassive@feddit.de 34 points 3 months ago (1 children)

That's decades of legacy for you...

I bet each step/arrow/decision had a good reason at some point, but most of them probably back when computers lived in caves and hunted their tapes using spears and rocks.

I feel like we're slowly reaching a point where the complexity is collapsing in on itself - just look at the absolute chaos a modern web app is.

[–] JackbyDev@programming.dev 3 points 3 months ago

I was referring more to the graphical representation that the actual flows.

[–] MajorHavoc@programming.dev 20 points 3 months ago

Agreed! It's cathartic to see it laid out so terrifying. Now I feel less bad for never understanding it.

[–] communism@lemmy.ml 9 points 3 months ago (1 children)

What do the differently coloured arrows mean? I'm confused.

[–] gamma@programming.dev 11 points 3 months ago* (last edited 3 months ago) (1 children)

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

File neither interactive login both
/etc/zshenv x x x x
${ZDOTDIR:-$HOME}/.zshenv x x x x
${ZDOTDIR:-$HOME}/.zprofile x x
${ZDOTDIR:-$HOME}/.zshrc x x
${ZDOTDIR:-$HOME}/.zlogin x x
${ZDOTDIR:-$HOME}/.zlogout x x

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.

[–] JackbyDev@programming.dev 3 points 3 months ago (1 children)

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.

[–] gamma@programming.dev 4 points 3 months ago

manually call the others

Yeah, most distros will set up source chains to make things nicer for users.

[–] mumblerfish@lemmy.world 4 points 3 months ago* (last edited 3 months ago) (1 children)

Is this a diagram for how it should work? Not how it actually works? Like I put my stuff in the ~/.bashrc, mostly because I think the debian one says like "put your fun stuff below here" or something. The green and grey lines go through the ~/.bashrc, but both of them go through the "no login" bubble in the diagram. But I know my ~/.bashrc works, so the diagram is a suggestion?

[–] JackbyDev@programming.dev 2 points 3 months ago

A lot of systems will call various inits from others to give you a more simplified flow. (Closer to what zsh does.) Check out some of those files in /etc/ it is calling as well as ~/.bash_profile. Or, you might not even be in a login shell!

[–] ulterno@lemmy.kde.social 3 points 3 months ago

Here's the seemingly original source for those who like to know.