1

I want to set the root level environment variable that comes from sh(1) so that it is shared across all shells: sh, bash, zsh, and fish.

I can see in /etc/profile there's a command /usr/libexec/path_helper -s which prints default values of PATH but it also has custom values set by other tools like gcloud, mono. How do those do this? I want to share my custom values as well.

I'm not going to add them to /etc/profile because that can be changed due to an update and I don't see gcloud/mono/conda specify their paths there. So what is the correct solution?

Any tips for keep all shells in sync would be very helpful.

I'm on macOS Catalina: 10.15.5 (19F101)

13
  • What OS? If Linux, what distro?
    – ilkkachu
    Jul 20, 2020 at 19:06
  • 1
    fish does not have the same syntax as bash/zsh for setting variables, so your goal is impossible. You must have a separate config file for fish. Jul 20, 2020 at 19:15
  • 2
    For Linuxes, one answer could be pam_env and /etc/environment, but I have no idea how the similar stuff works on macOS.
    – ilkkachu
    Jul 20, 2020 at 19:21
  • 1
    Possibly useful - as a starting point - on Ask Different: Defining environment variables with launchd/launchctl. Though I didn't see any mention to macOS 10.15, I couldn't tell if the linked solution are going to work in your case.
    – fra-san
    Jul 20, 2020 at 20:00
  • 1
    As at unix.stackexchange.com/q/599443/5132 , this question is based upon a lot of confusion. That's nowhere near "all shells". sh is not some common base for all shells. And the idea of a sh "root level" is confused about how login works and how processes inherit environment variables.
    – JdeBP
    Jul 20, 2020 at 21:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.