Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Apple > Operating Systems

  • Print
  • + Share This
This chapter is from the book

Configuring Your Shell

The first thing you need to know is which shell you are using. The default shell on Mac OS X is tcsh. Many experienced Unix users prefer the bash shell (see Chapter 15, "More Open-Source Software" at http://www.peachpit.com/vqp/umox, to learn how to install bash).

It's very easy to find out which shell you are using. One simple command line will show you.

To determine which shell you are using:

  • echo $SHELL

$SHELL is an environment variable (more about these in the "Environment Variables" section below) that contains the full path of the shell you are using. Unless you have changed from the Mac OS X default, you will see /bin/tcsh (Figure 7.1).

Figure 7.1Figure 7.1 Displaying the $SHELL environment variable.

Tips

  • You can change the shell that the Terminal program uses by selecting Preferences from the Terminal menu. If you want to change your default login shell (so that the new shell is used no matter how you get to the command line), then see "Changing a User's Login Shell" in Chapter 11.

  • See Chapter 11, "Introduction to System Administration," for instructions on changing your log-in shell not only within the Terminal application but also for when you connect to your Mac from another machine over a network using a command-line interface.

To configure your shell, edit the appropriate configuration file(s). Table 7.2 lists the con-figuration files for the most common shells.

Unless you have changed the default Mac OS X setup, you configure your shell by editing your ~/.tcshrc file.

Note that some of the files are the systemwide defaults (those located in the /etc directory), and some are user files (located in each user's home directory). Also, some configuration files are only executed for interactive shells—these are shells that give you a command-line prompt (as opposed to a shell program started by a script or other process).

Table 7.2 Common Configuration Files

Shells and Configuration Files in Order of Execution. Remember that the ~ character is short hand for " your home directory. "

Shell Name and Description

TCSH

/etc/csh.cshrc

Systemwide configuration file for the tcsh and csh shells. This is the first file that tcsh executes when it starts up (Figure 7.2).

 /etc/csh.login

Systemwide configuration for tcsh and csh, executed only for interactive shells.

~/.tcshrc

The main personal configuration file for your tcsh shell. If tcsh doesn't find this, it looks for a .cshrc file.

~/.login

This file is executed after the .tcshrc file, but only if the shell is an interactive log-in shell. It won't be used if some other process is starting the shell.

~/.logout

Tcsh executes this file when you log out of an interactive shell.

BASH

/etc/profile

Systemwide configuration file for the bash and sh shells.

~/.bash_profile

The first personal configuration file that bash looks for.

~/.bashrc

This file is executed for interactive shells but not for your log-in shell (the shell that starts up when you open each Terminal window).

~/.bash_logout

Executed when you log out from a bash log-in shell.


Figure 7.2Figure 7.2 /usr/share/init/tcsh/rc is the main tcsh configuration file. This is a shell script written in tcsh.

  • + Share This
  • 🔖 Save To Your Account