05.01.2013 Views

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

326<br />

CHAPTER 18 INTRODUCING DARWIN AND THE SHELL<br />

NOTE Traditionally, things in the profile files would get read when you logged into a terminal,<br />

and things in the bashrc files would get read each time you launched a new shell. This isn’t<br />

exactly how these things work anymore, but it’s still nice to keep the content of each separate.<br />

One common environmental variable that you may want to set is the $PATH variable. The<br />

$PATH variable describes where your shell will look for executables when you attempt to launch<br />

one from the command line. By default, your $PATH is set to include /bin, /sbin, /usr/bin,<br />

/usr/sbin, and /usr/X11/bin (in the /etc/profile file). However, if you begin to install new executables,<br />

or even write your own, you may find that you need to add additional directories to<br />

your $PATH. The syntax to add a directory to the $PATH is as follows:<br />

$PATH=/new/directory:/another/new/direcotry:"${PATH}"<br />

You can add as many directories as you need, separated by a colon. The "${PATH}" at the end<br />

represents your existing path; without it, any of the default $PATH directories will be removed<br />

from your $PATH. To have your path updated each time you launch a shell, it’s best just to put this<br />

info in your .bash_profile. For example, my current .bash_profile looks like this:<br />

### .bash_profile ###<br />

# a good place for environmental variables #<br />

### $PATH ###<br />

if [ -d /usr/local/bin ] ; then<br />

PATH=/usr/local/bin:"${PATH}"<br />

fi<br />

if [ -d /usr/local/mysql/bin ] ; then<br />

PATH=/usr/local/mysql/bin:"${PATH}"<br />

fi<br />

if [ -d ~/bin ] ; then<br />

PATH=~/bin:"${PATH}"<br />

fi<br />

if [ -d /opt/local/bin ] ; then<br />

PATH=/opt/local/bin:"${PATH}"<br />

fi<br />

### include .bashrc if one exists ###<br />

if [ -f ~/.bashrc ]; then<br />

. ~/.bashrc<br />

fi<br />

Any line beginning with # is a comment. Here I use some of the built-in scripting functionality<br />

to check if common executable directories exist—if they do, then they are automatically<br />

added to my $PATH.<br />

The last part checks to see if I have a .bashrc file, and if I do, it includes that as well.<br />

The bashrc files generally contain variables and commands that are specific to the shell. For<br />

example, the default /etc/bashrc file sets the prompt variable. Other things that are generally<br />

included in the bashrc files are common aliases and shell functions.<br />

For example, my current <strong>OS</strong> X .bashrc file is simply the following:<br />

### .bashrc file ###<br />

# This file is for shell-specific stuff #<br />

# $PATH and other env variables should go in the .bash_profile #

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!