What is the TERM_PROGRAM and TERM_PROGRAM_VERSION environment variables used for?

I assume it is just an environment variable that stores your default program that you want to use to bring up a terminal window. There are several different applications on OS X that give you a Unix-like command prompt. The default is the Apple-supplied terminal in /Applications/Utilities/Terminal.app. If you've installed some other terminal like iTerm or AquaTerm, then this variable is likely set to that particular application, if it is your default. The name Apple_Terminal must be some internal shortcut to the full /Applications/Utilities/Terminal.app path.

Just like your SHELL variable, this is the default that is used in scripts or other programs, unless it is specified in those programs specifically, whereupon the default gets overwritten.

EDIT: actually this answer on stack overflow seems to confirm my suspicions.


TERM_PROGRAM is used in /etc/zshrc and /etc/bashrc to run commands that are specific to the terminal program you are using when they open a shell. By default, macOS supplies /etc/zshrc_Apple_Terminal and /etc/bashrc_Apple_Terminal which do some extra work to manage the current working directory and support suspending and resuming the terminal. If you use another terminal program, you can place a file at /etc/zshrc_$TERM_PROGRAM or /etc/bashrc_$TERM_PROGRAM and it will be executed when your terminal program opens a shell. You have to ensure that your terminal program sets a value for $TERM_PROGRAM of course.