Using the Unix Shell on Mac OS X

Default Shell | Clipboard | Environment Settings

I use, though there are other terminal emulation programs available. Additional shell tips.

Default Shell

The default shell program can be set in, though this is a poor method, as other terminal programs will likely not honor this setting. Use chsh(1) (or a directory editor if the system is slaved to some directory service) to update the shell. Custom shells may result in an error:

chsh: …: non-standard shell

This can be corrected by adding the path to the custom shell in the /etc/shells file.

Another trick is to exec zsh from a shell startup file that is read by whatever the default shell is, usually ~/.profile. However, this requires safeguards to ensure that the new shell does not again read ~/.profile and thereby create an infinite exec loop.


Use the pbcopy and pbpaste commands to interact with the clipboard.

$ echo /tmp | pbcopy
$ ls -d `pbpaste`

On some versions of Mac OS X, the Apple supplied screen(1) program would cause problems for these utilities. Upgrade to the latest OS X, or compile screen manually (or via a ports or package system).

Environment Settings

Sharing process environment variables with other programs (such as BBEdit) on Mac OS X is difficult. Environment variables for all programs can be set in the ~/.MacOSX/environment.plist file, though this requires a logout for changes to take effect. If this is a problem, place a shell script wrapper between the program being run and the caller. For example, a BBEdit filter or Xcode user script could first run:

exec the_real_program "$@"

As this would set any shell configuration listed in the ~/.zshenv file. The shell script wrapper could also source environment settings from a known location (. ~/.somerc). This avoids the need to duplicate the shell environment into the environment.plist file, and offers dynamic updates should the environment settings need to be changed without logging out.