I am curious how does iterm2 work? I mean it would be a gargantuan task to re-implement all the unix commands and I guess it somehow uses the built-in terminal under the covers to run the actual commands but how?

1 Answer 1


Both applications: built-in Apple Terminal and iTerm2 are only terminal emulators. They do not implement any commands, they just take care of the display.

When you open either a Terminal or an iTerm2 window, it automatically runs a shell (like bash or ksh). This is the program that interprets most of the commands that you know as CLI. When you type a command into a shell, it first tries to match it with its internal set of commands and interprets it accordingly. If a command is not found, the shell will try to find a program which name matches the command. This is what you might perceive aa "unix commands", however they are just standalone programs.

For example: If you run a Terminal on a Mac, it runs bash shell by default. Then if you type date, the shell will find it is not an internal shell command, so it will search the disk (it will search only in places defined in a so called "PATH environment variable") and it will most likely find a program in the following place /bin/date. The shell will execute this program. The Terminal will then print the standard output of the date command in its window.

iTerm2 does not use Terminal in the background, but it will run the same shell. So the flow is: iTerm2 runs bash (by default), bash then executes a date command and date command will send its output to the iTerm2 which will display the characters for the user.

  • thanks. so how does one go about writing their own emulator? how are all the bash and unix commands accessed in a programming language like C, C++ etc.?
    – Steve
    Sep 18, 2015 at 4:13
  • 1
    Here: github.com/black-screen/black-screen is an example of a new terminal emulator recently getting traction. You can see how it is being actively developed. bash commands can only be executed by calling bash program and passing a script with commands to it. Other external commands can be called either from this script or on their own.
    – techraf
    Sep 18, 2015 at 4:20
  • 1
    This is not really a Mac-specific question, so you find more information on StackOverflow. For example: stackoverflow.com/questions/18094242/…
    – techraf
    Sep 18, 2015 at 4:29

You must log in to answer this question.

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