Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
5Activity
0 of .
Results for:
No results containing your search query
P. 1
THE_UNIX_SHELL_GUIDE

THE_UNIX_SHELL_GUIDE

Ratings: (0)|Views: 39|Likes:
Published by api-19935880

More info:

Published by: api-19935880 on Dec 02, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

THE UNIX SHELL GUIDE
Norman J. Buchanan
Douglas M. Gingrich
The UNIX Shell Guide

by Norman J. Buchanan & Douglas M. Gingrich
Copyright \u00a91996 University of Alberta, Department of Physics. All rights reserved.
UNIX is a registered trademark of Novell.
Many of the designations used by manufactures and sellers to distinguish their products
are claimed as trademarks. Where those designations appear in this book, we are aware of
a trademark claim.
While every precaution has been taken in the preparation of this book, the authors assume
no responsibility for errors or omissions, or for damages resulting from the use of the
information contained here in.

THE UNIX SHELL GUIDE..................................................................................... . . . . . . . . . . 1
Preface.................................................................................................................................. 2
What is a Shell?................................................................................................................... 3
UNIX Commands versus Built in Shell Commands............................................................ 4
Interactive and Sub Shells................................................................................................ . . . . 5
Command Line Parsing........................................................................................................ 5
Redirection........................................................................................................................... 6
The Bourne Shell................................................................................................................. 7
A Bit of History................................................................................................................... 8
Getting to Know the Bourne Shell....................................................................................... 8
Multiple Commands Per Line.............................................................................................. 9
Redirection and Pipelines....................................................................... . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Redirection and Pipelines....................................................................... . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Special Characters.......................................................................................................... . . . . 12
Variables........................................................................................................ . . . . . . . . . . . . . . . . . . . . 13
Variable Substitutions.......................................................................................... . . . . . . . . . . 14
Parameters............................................................................................................... . . . . . . . 15
Environmental Variables.................................................................... . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Special Variables................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Bourne Shell Programming................................................................................................ 17
Testing and Branching................................................................................................... 18
String Comparisons........................................................................................................ 20
Testing Files............................................................................................................ . . . . . . . 20
Loop Control.................................................................................................................. 25
Exiting Loops Early.................................................................................. . . . . . . . . . . . . . . . . . 26
Input and Output (I/O)................................................................................................... 27
Advanced Programming Topics.................................................................................... 28
Functions............................................................................................................. . . . . . . . 29
Trapping Errors.......................................................................................................... 30

Dot Files.................................................................................................................. . . . . . . . 31
The C Shell........................................................................................................................ 32
A Bit of History................................................................................................................. 32
Getting Started with the C Shell........................................................................................ 33
Command Execution...................................................................................................... . . . . 33
Redirection and Pipelines....................................................................... . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Filename Substitution................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . 36
Filename Completion......................................................................................................... 37
Special Characters.......................................................................................................... . . . . 38
Command History.............................................................................................................. 39
Aliases................................................................................................................................ 41
Variables........................................................................................................ . . . . . . . . . . . . . . . . . . . . 42
Variables........................................................................................................ . . . . . . . . . . . . . . . . . . . . 44
Array Variables................................................................................................... . . . . . . . . . . . 45
Global or Environment Variables................................................................. . . . . . . . . . . . . . . . . . 46
Parameters............................................................................................................... . . . . . . . 47
Special Read Only Variables.................................................................... . . . . . . . . . . . . . . . . . . . . . 48
Variable Modifiers........................................................................................... . . . . . . . . . . . . . . 48
C Shell Programming..................................................................................................... . . . . 49
Testing and Branching................................................................................................... 50
Signal Handling............................................................................................................. 57
Job Control......................................................................................................................... 58
Special Files......................................................................................................... . . . . . . . . . . . . . . 60
Introduction to UNIX Security...................................................................................... 61

Preface

This book is intended to assist UNIX users in understanding and dealing with five of the
most popular UNIX shells: the Bourne shell (sh); the C shell (csh); the Korn shell (ksh);
the TC shell (tcsh); and the Z shell (zsh). The idea came mainly out of frustration in
trying to get understandable information on shell usage. Much has been written on UNIX
as a whole but rarely is more than a chapter on Bourne shell or C shell included, and
these usually prove to be little more than a loose translation of the online manual (man)
pages. Shells are certainly sophisticated and powerful enough to warrant a detailed
treatment on their own. The man pages, as any UNIX user is well aware, are fine for
listing commands and associated flags but that is where the usefulness ends. Examples
are seldom found and some of the features are covered in one or two lines of text, leaving
the user to overlook their importance. The man pages are, after all, meant to act as a
reference more than an actual instruction manual and should be treated as such.

Hopefully this book will achieve two goals. First, to give a clear and concise look at each
of five shells. Each shell will be examined from the point of view of interactive work
features, and then from a shell programming point of view. Examples will be used as
much as possible to lend illustration to the concepts presented in the text, especially in the
area of shell programming. Hopefully, the range of examples will be such that there will
be something that everyone can use. New UNIX users will then be able to pick up on
some of the powerful features of the particular shell(s) of interest and develop a feel for
shell programming, which is probably the most flexible and exciting feature of UNIX
shells in general. The second goal of the book is to allow users the opportunity to
examine the features of the various shells covered and determine which shell(s) might be
right for them. Each shell will be contrasted with the others to demonstrate the strengths
and weaknesses compared with the rest. This we hope will make this book truly unique.
As with most other things in life, choice can make things more difficult than expected.
While it is nice to have choice, making a choice can require a level of research that most
people just do not have the time to invest. Sometimes the number of choices is not even
known, further complicating the decision process - how can you make a choice if you do
not know what the choices are? In this book enough information will be presented so the
users can make educated decisions without spending the time trying to gather the
information on their own, or having to make sense of it afterwards.
Users new to UNIX will be able to become acquainted with the shell they are provided
with, learning the details of shell usage until they are able to decide if a different shell
may better suit their needs. Even users who have spent many years mastering a particular
shell may find that some of the more recent shells provide powerful features that they can
tailor to their specific needs. If any of the shells mentioned in this book are not available
on your machine, most system administrators can be persuaded to load them on to your
machine for use. To further assist in making the various shells available, FTP sites where
they can be found are included.
This book will be of great interest to users of personal computers who are considering
moving or have just moved to the new UNIX-compatible operating system for the
personal computer - LINUX. LINUX is distributed freely in electronic form and for low
cost from many vendors. The standard software distribution includes many of the shells
described in this book.
Norman J. Buchanan
Douglas M. Gingrich

What is a Shell?

What is a shell? A shell is a command interpreter. While this is certainly true it likely
doesn't enlighten the reader any further. A shell is an entity that takes input from the user
and deals with the computer rather than have the user deal directly with the computer. If
the user had to deal directly with the computer he would not get much done as the
computer only understands strings of 1's and 0's. While this is a bit of a misrepresentation
of what the shell actually does (the idea of an operating system is neglected) it provides a
rough idea that should cause the reader to be grateful that there is such a thing as a shell.
A good way to view a shell is as follows. When a person drives a car, that person doesn't

Activity (5)

You've already reviewed this. Edit your review.
1 hundred reads
muni123ss liked this
larlen liked this
skksysfa liked this
Kate Antoinette liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->