<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
I know we are getting a little off-topic here, but I found this response quite helpful in resolving some misunderstandings I had. So I would like to ask some clarifying questions, mostly related to login vs non-login shells, and interactive vs non-interactive
 shells.
<div class=""><br class="">
</div>
<div class="">If I understand correctly, the “best practice” would be to put PATH variables in ~/.zshenv, and then let path_helper do its thing.  Then, any changes in the order of the paths for login shells can go in ~/.zprofile. In that case, the PATH would
 be available pretty much everywhere, since anything spawned from the MacOS desktop (Aquamacs, Terminal, etc) would always be treated as a login shell (since I need to log in to get to the desktop). Non-login shells would get the PATH from ~/.zshenv, but not
 the changes from ~/.zprofile. Do I have that right?</div>
<div class=""><br class="">
</div>
<div class="">What else should go in ~/.zshenv ? I would think that environment variables that will rarely change would go there.  For example, I am a heavy R user, so should  ~/.zshenv should include R_HOME, R_PROFILE, etc.?</div>
<div class=""><br class="">
</div>
<div class="">I am still a little confused about interactive vs non-interactive shells. When I launch an interactive R session from Terminal, or run a batch R script from the command line, I can see zshrc is loaded.  Also, if I launch an Aquamacs session from
 the command line (launching the GUI), zshrc is loaded.  But clicking on the Aquamacs icon in the Dock, zshrc it is not.  Is this because everything spawned from Terminal is interactive, but anything launched from the desktop directly is not?</div>
<div class=""><br class="">
</div>
<div class="">Thanks.</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On Jan 2, 2021, at 3:10 PM, Ettore Aldrovandi <<a href="mailto:ealdrov@math.fsu.edu" class="">ealdrov@math.fsu.edu</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Yeah, that’s order _overall_ (mostly) but whether any of those files gets read depends on the kind of shell instance is running. Non login shells will _not_ read /etc/.zprofile and ~/.zprofile. Non interactive shells will _not_ read ~/.zshrc.  Most of the time,
 .zprofile will not be read, because, for example, single Terminal.app instances do not run login shells (they’re all children of the app) unless you explicitly configure them to be so.
<div class=""><br class="">
</div>
<div class="">Also, as per man page, /etc/zshenv is _always_ read first (can’t override this).<br class="">
<div class=""><br class="">
</div>
<div class="">The PATH problems most people encounter are caused by how /etc/zprofile  is set. Note, even if the shell instance is not a login one, it will have inherited its environment from a login one. So, if say PATH is set in ~/.zshenv, as it should be,
 the shell reads it, and _then_ reads /etc/zprofile. The way MacOS is set up, /etc/zprofile calls /usr/libexec/path_helper which re-synthesizes the path based on: (1) /etc/paths, and (2) the content of /etc/paths.d resulting in a path that will _always_ have
 system directories in front of whatever was defined in .zshenv. </div>
<div class=""><br class="">
</div>
<div class="">If nothing depends on the order in the PATH, then fine. But if you for whatever reason need something in a specific order, say because you have different versions of the same utility installed in different locations, then you need to cater for
 that situation specifically. </div>
<div class=""><br class="">
</div>
<div class="">So, your solution is one of the good ones which works because .zprofile is read after /etc/zprofile has done its thing with path_helper. The only caveat is what might happen if you spawn a non-interactive non-login shell.</div>
<div class=""><br class="">
</div>
<div class="">Here’s what I do:  my TeXLive, HomeBrew paths are set by putting one-liners in /etc/paths.d, in the same way XQuartz is set.  I don’t care for the specific order. My $HOME/bin and $HOME/.cabal/bin are added to PATH in ~/.zshenv for the reason
 I mentioned above. But since I also care that $HOME/.cabal/bin should be first in the path, I have that set in .zprofile. In fact it’s the only thing it does.</div>
<div class=""><br class="">
</div>
<div class="">Oh, and /etc/zshrc_Apple_Terminal  is called by /etc/zshrc. </div>
<div class=""><br class="">
</div>
<div class="">—Ettore</div>
<div class=""><br class="">
<blockquote type="cite" class="">
<div class="">On Jan 2, 2021, at 15:26, Braun, Michael <<a href="mailto:braunm@mail.smu.edu" class="">braunm@mail.smu.edu</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
I had a similar issue during the summer, where environment variables I was setting in .zshenv were not being picked up. It turns out the order of loading goes like this:
<div class=""><br class="">
</div>
<div class="">~/.zshenv</div>
<div class="">/etc/zprofile<br class="">
<div class="">~/.zprofile</div>
<div class="">/etc/zshrc<br class="">
<div class="">~/.zshrc</div>
</div>
<div class="">
<div class="">
<div class="">~/.zlogin</div>
</div>
</div>
<div class=""><br class="">
</div>
<div class="">(There is also a /etc/zshrc/Apple_Terminal file, but I don’t know when that runs).</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">So you need to be sure that, for example, something in /etc/zshrc is not overriding something in ~/.zprofile.  This is exactly what was happing when I set my Terminal prompt format in ~/.zshenv or ~/.zprofile.  For some reason, MacOS defines a
 default prompt format in /etc/zshrc, which was overwriting my profile. Maybe something similar is happening to you.</div>
<div class=""><br class="">
</div>
<div class="">So here’s what works for me.  I set all of my system environment variables (like PATH) in ~/.zprofile.  Anything related to my Terminal login shell (like prompt colors, formats, themes, etc) goes in ~/zshrc.  And it works!  I can see all of my
 ~/.zprofile environment variables within Aquamacs.</div>
<div class=""><br class="">
</div>
<div class="">This appears to be the *complete opposite* of some advice I’ve seen online.  All I can say is that everything works with PATH in ~/.zprofile and terminal-related variables in ~/.zshrc.</div>
<div class=""><br class="">
</div>
<div class="">
<div class=""><br class="">
<blockquote type="cite" class="">
<div class="">On Jan 2, 2021, at 8:33 AM, Ettore Aldrovandi <<a href="mailto:ealdrov@math.fsu.edu" class="">ealdrov@math.fsu.edu</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Dear Win, Roussanka,
<div class=""><br class="">
</div>
<div class="">Happy New Year!   </div>
<div class=""><br class="">
</div>
<div class="">One more information morsel. An unrelated issue made me realize that Aquamacs, and also other variants like YAMAMOTO Mitsuharu’s Emacs port, which I also use,  read .zprofile when launched with a double-click. </div>
<div class=""><br class="">
</div>
<div class="">To recap, in the Z shell .zprofile is read by login shells. If they are not interactive, as it appears the ones run under the window server are, they will not read .zshrc, so anything set there, in particular PATH, will not be read. So, it’s good
 news, at least to me, that .zprofile is read: I had an issue that I wanted  my $HOME/.cabal/bin in front of the path (in emacs too), and exporting from .zprofile did it. (I have to still do the same export from .zshrc for the Terminal: its shells are non-login
 and interactive, so .zprofile is not read.)</div>
<div class=""><br class="">
</div>
<div class="">All the best and a happy and safe 2021 to everyone,</div>
<div class=""><br class="">
</div>
<div class="">—Ettore<br class="">
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
<br class="">
<br class="">
<div class="">
<div dir="auto" style="caret-color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div style="font-family: Helvetica; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div class="">--------------------------</div>
<div class="">Michael Braun</div>
<div class="">Associate Professor of Marketing, and</div>
<div class="">  Corrigan Research Professor</div>
<div class="">Cox School of Business</div>
<div class="">Southern Methodist University</div>
<div class="">Dallas, TX 75275</div>
<div class=""><a href="mailto:braunm@smu.edu" class="">braunm@smu.edu</a></div>
<div class=""><br class="">
</div>
</div>
<br class="Apple-interchange-newline">
</div>
<br class="Apple-interchange-newline">
</div>
<br class="Apple-interchange-newline">
</div>
<br class="Apple-interchange-newline">
<br class="Apple-interchange-newline">
</div>
<br class="">
</div>
<br class="">
_____________________________________________________________<br class="">
MacOSX-Emacs mailing list<br class="">
<a href="mailto:MacOSX-Emacs@email.esm.psu.edu" class="">MacOSX-Emacs@email.esm.psu.edu</a><br class="">
<a href="https://email.esm.psu.edu/mailman/listinfo/macosx-emacs" class="">https://email.esm.psu.edu/mailman/listinfo/macosx-emacs</a><br class="">
List Archives: http://dir.gmane.org/gmane.emacs.macintosh.osx<br class="">
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
<br class="">
_____________________________________________________________<br class="">
MacOSX-Emacs mailing list<br class="">
<a href="mailto:MacOSX-Emacs@email.esm.psu.edu" class="">MacOSX-Emacs@email.esm.psu.edu</a><br class="">
https://email.esm.psu.edu/mailman/listinfo/macosx-emacs<br class="">
List Archives: http://dir.gmane.org/gmane.emacs.macintosh.osx<br class="">
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>