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.

Extending the Power<br />

of Darwin<br />

After the previous chapter, we hope you are at least somewhat comfortable working in<br />

Darwin. In this chapter, we’ll move on and show how to extend the power of Darwin<br />

by covering the following:<br />

• An introduction to shell scripting<br />

• An overview of Perl, Python, and Ruby, which are three powerful scripting languages<br />

included with <strong>Leopard</strong><br />

• How to find and install a range of additional applications using <strong>Mac</strong>Ports and Fink<br />

• How to custom compile a Darwin application from the source code<br />

Getting Started with Shell Scripting<br />

CHAPTER<br />

19<br />

Shell scripting has been a staple in Unix since the first shell. A shell script allows you to add a<br />

series of shell commands to a file so that these commands can be easily run over and over. You<br />

can see an example of the value of this by examining the start-up process of <strong>Leopard</strong>. During the<br />

start-up, the shell script /etc/rc is started; this file begins a series of processes that effectively<br />

start up, configure, and maintain many of the necessary <strong>OS</strong> and networking functions that occur<br />

during start-up.<br />

NOTE It’s not recommended that you edit this /etc/rc since it’s possible that your system will<br />

not start up correctly if you make a mistake; however, you’ll see that toward the bottom of this<br />

script there is a check for the existence of /etc/rc.local. If this file exists, it will include it and<br />

execute any scripting contained in it. If you want to include your own scripts that will execute<br />

every time you boot the <strong>OS</strong>, this file should be created if it doesn’t exist (which by default it<br />

doesn’t), and your additional start-up scripts should be added to it.<br />

Writing a shell script can be as easy as just listing a series of any of the commands you may<br />

enter at the command line; however, shell scripts can also accept external variables and may contain<br />

simple if...then logic and loops. I’ll briefly explain all of these things, but first let’s take a<br />

look at a sample shell script (the line numbers are for reference and shouldn’t be typed into your<br />

script):<br />

329

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

Saved successfully!

Ooh no, something went wrong!