25.03.2013 Views

Copyright Sams Teach Yourself Shell Programming in 24 Hours

Copyright Sams Teach Yourself Shell Programming in 24 Hours

Copyright Sams Teach Yourself Shell Programming in 24 Hours

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Although the C shell did not catch on for scripts, it has become extremely popular for <strong>in</strong>teractive use. Some<br />

of the key improvements responsible for this popularity follow:<br />

● Command History. You can recall commands you previously executed for re- execution. You can<br />

also edit the command before it is re-executed.<br />

● Aliases. You can create short mnemonic names for commands. Aliases are a simplified form of the<br />

Bourne shell functions.<br />

● File Name Completion. You can have the C shell automatically complete a filename by just typ<strong>in</strong>g a<br />

few characters of the file's name.<br />

● Job Controls. The C shell enables you to execute multiple processes and control them us<strong>in</strong>g the<br />

jobs command.<br />

The C shell is usually <strong>in</strong>stalled on most systems as /b<strong>in</strong>/csh.<br />

The TENEX/TOPS C shell, tcsh, is a newer version of the C shell that enables you to scroll through the<br />

command history us<strong>in</strong>g the up and down arrow keys. It also enables you to edit commands us<strong>in</strong>g right and<br />

left arrow keys.<br />

Although it is widely available <strong>in</strong> educational UNIX mach<strong>in</strong>es, tcsh is not always present on corporate UNIX<br />

mach<strong>in</strong>es. For more <strong>in</strong>formation on obta<strong>in</strong><strong>in</strong>g tcsh, take a look at the follow<strong>in</strong>g URL:<br />

http://www.primate.wisc.edu/software/csh-tcsh-book/<br />

This page <strong>in</strong>cludes <strong>in</strong>formation on obta<strong>in</strong><strong>in</strong>g and <strong>in</strong>stall<strong>in</strong>g tcsh <strong>in</strong> both source and b<strong>in</strong>ary form.<br />

The Korn <strong>Shell</strong><br />

For a long time, the only two shells to choose from were the Bourne shell and the C shell. This meant that<br />

most users had to know two shells, the Bourne shell for programm<strong>in</strong>g and the C shell for <strong>in</strong>teractive use.<br />

To rectify this situation, David Korn of AT&T Bell Labs wrote the Korn shell, ksh, which <strong>in</strong>corporates all the<br />

C shell's <strong>in</strong>teractive features <strong>in</strong>to the Bourne shell's syntax. For this reason, the Korn shell has become a<br />

favorite with users.<br />

In recent years, most vendors have started to ship the Korn shell with their versions of UNIX. Usually you will<br />

f<strong>in</strong>d it <strong>in</strong>stalled as /b<strong>in</strong>/ksh or /usr/b<strong>in</strong>/ksh.<br />

In general, ksh can be treated as fully compatible with sh, but some differences will prevent scripts from<br />

function<strong>in</strong>g correctly. These exceptions are noted throughout the book.<br />

Some of the additional features that the Korn shell br<strong>in</strong>gs to the Bourne shell <strong>in</strong>clude the follow<strong>in</strong>g:<br />

● Command history and history substitution<br />

● Command aliases and functions<br />

● File name completion<br />

● Arrays (see Chapter 7)<br />

● Built-<strong>in</strong> <strong>in</strong>teger arithmetic (see Chapter 8)

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

Saved successfully!

Ooh no, something went wrong!