Unix for Mac OS X 10.4 Tiger: Visual QuickPro Guide (2nd Edition)
The first thing you need to know is which shell you are using. The default shell on Mac OS X is 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/bash ( Figure 7.1 ).
Figure 7.1. Displaying the contents of the SHELL environment variable.
localhost:~ vanilla$ echo $SHELL /bin/bash localhost:~ vanilla$
-
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), see "Changing a user 's login shell" in Chapter 11, "Introduction to System Administration."
-
See Chapter 11 for instructions on changing your login 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 configuration files for the most common shells .
Table 7.2. Common Configuration Files
| S HELLS AND C ONFIGURATION F ILES IN O RDER OF E XECUTION (REMEMBER THAT THE ~ CHARACTER IS SHORTHAND FOR YOUR HOME DIRECTORY ) | |
|---|---|
| BASH | |
| /etc/profile | Systemwide configuration file for the bash and sh shells ( Figure 7.2 ). |
| /etc/bashrc | Systemwide configuration file for bash interactive shells ( Figure 7.3 ). |
| ~/.bash_profile | The first personal configuration file that bash looks for. |
| ~/.bashrc | This file is executed for interactive shells unless the shell is your login shell (the shell that starts up when you open each Terminal window). |
| ~/.bash_logout | Executed when you log out from a bash login shell. |
| 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. |
| /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 login 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. |
Figure 7.2. /etc/profile is the main sh and bash configuration file. This is a shell script written in sh .
# System-wide .profile for sh(1) PATH="/bin:/sbin:/usr/bin:/usr/sbin" export PATH if [ "${BASH-no}" != "no" ]; then [ -r /etc/bashrc ] && . /etc/bashrc fi
Figure 7.3. /etc/bashrc is the systemwide configuration file for bash interactive shells.
# System-wide .bashrc file for interactive bash(1) shells. if [ -n "$PS1" ]; then PS1='\h:\w \u$ '; fi # Make bash check it's window size after a process completes shopt -s checkwinsize
Unless you have changed the default Mac OS X setup, you configure your shell by editing your ~/.bash_profile 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 executed only for interactive shellsthese are shells that give you a command-line prompt (as opposed to a shell program started by a script or other process).