0

Answers like this one show that on a Mac, .bash_profile gets run every time a new terminal window opens.

Is there a shell config file for Mac OS that only runs when Terminal.app starts running and doesn't run for every new terminal window?

Community
  • 1
  • 1
YPCrumble
  • 26,610
  • 23
  • 107
  • 172
  • There is not. The reason terminal emulators start a login shell for each window is that the terminal emulators themselves are not started from a `bash` login session. – chepner Feb 06 '17 at 13:51
  • @chepner that isn't the case - see for instance [here](http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html) for an explanation. If emulators all started a login shell for each window there would be no reason for a different file for `.bash_profile` and `.bashrc`, at least on a Linux machine. – YPCrumble Feb 06 '17 at 14:18
  • I'm not sure how that contradicts what I wrote. That just explains why `.bash_profile` is used instead of `.bashrc`; I'm explaining why running a login shell makes sense for Mac OS X emulators in the first place. – chepner Feb 06 '17 at 14:26

1 Answers1

0

Is there a shell config file for Mac OS that only runs when Terminal.app starts running and doesn't run for every new terminal window?

There isn't, and there's no need to.


In Linux, the GUI frontend acts as a sh login shell, executing /etc/profile and ~/.profile. Any shell run in a terminal emulator in that session will thus inherit the resulting environment.

In MacOS, the GUI frontend does not do that. So to compenstate, Terminal.app is set up by default to run a shell inside it as a login shell, creating its own "login session" with the necessary environment.

As such, there's no need to run anything separately on Teminal.app's start.

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152