After running:

env  ; #from with in terminal

I see the following output:

TERM_PROGRAM=Apple_Terminal  ;#Not sure Terminal.app
TERM_PROGRAM_VERSION=273     ;#The CFBundleVersion of Terminal.app

After trying to put meaning to each of the variables listed I can't really find any definitive sources for what exactly the TERM_PROGRAM and TERM_PROGRAM_VERSION variables are used for. Man pages and Apropos are not showing anything explaining it, and Google is not as well. Clearly it is relating to some kind of Apple specific setting in Mac OS X, just not sure what?

  • 3
    This might be nothing more than an informational variable of the running terminal client to use in scripting for example. For example, it lists iTerm.app for me.
    – Gerry
    Commented Mar 6, 2012 at 15:38

3 Answers 3


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.

  • Your answer makes sense, but would you mind testing out your hypothesis in some way and update your answer with your findings? Commented Mar 7, 2012 at 7:19
  • Well, for example, @Gerry listed in the comment to the question that the TERM_PROGRAM variable listed iTerm.app for him. If he can chime in and say whether or not that is his default terminal, that should be sufficient. I don't know, off the top of my head a program that launches a terminal to test this - do you?
    – cm2
    Commented Mar 7, 2012 at 16:51
  • See the edit to the answer - it seems this has already been answered before on stack overflow.
    – cm2
    Commented Mar 7, 2012 at 17:46
  • 3
    To confirm: yes, TERM_PROGRAM is set to Apple_Terminal by Terminal to identify itself, and no other program should set it to that value. And TERM_PROGRAM_VERSION is the current version of the program identified with TERM_PROGRAM. You can use that, for example, to check whether Terminal is new enough to support some feature you want to use, like the escape sequences for setting the working directory and represented file (new in Lion).
    – Chris Page
    Commented Mar 10, 2012 at 21:48

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.


Use Case: I use iterm2, Apple_Terminal, and emacs vterm with zsh.

I put the below code in the theme setting section of ~/.zshrc to use different zsh theme in each terminal

          if [ "$TERM_PROGRAM" = "Apple_Terminal" ]; then
          elif [ "$TERM_PROGRAM" = "iTerm.app" ]  &&  [ "$INSIDE_EMACS" = "vterm" ]; then

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .