Instant Access to Learning the bash Shell Unix Shell Programming Third Edition Cameron Newham ebook Full Chapters
Instant Access to Learning the bash Shell Unix Shell Programming Third Edition Cameron Newham ebook Full Chapters
https://ebookfinal.com/download/pro-bash-programming-second-edition-
scripting-the-gnu-linux-shell-johnson/
https://ebookfinal.com/download/learning-unix-for-os-x-going-deep-
with-the-terminal-and-shell-2nd-edition-dave-taylor/
https://ebookfinal.com/download/ghost-in-the-shell-2nd-edition-
masamune-shirow/
https://ebookfinal.com/download/kant-s-observations-and-remarks-a-
critical-guide-shell/
SSH The Secure Shell The Definitive Guide 1st Edition
Daniel J. Barrett
https://ebookfinal.com/download/ssh-the-secure-shell-the-definitive-
guide-1st-edition-daniel-j-barrett/
https://ebookfinal.com/download/ssh-the-secure-shell-the-definitive-
guide-second-edition-daniel-j-barrett/
https://ebookfinal.com/download/harnessing-the-uefi-shell-moving-the-
platform-beyond-dos-second-edition-michael-rothman/
https://ebookfinal.com/download/linux-command-line-and-shell-
scripting-bible-2nd-edition-richard-blum/
https://ebookfinal.com/download/oral-culture-and-catholicism-in-early-
modern-england-1st-edition-alison-shell/
Learning the bash Shell Unix Shell Programming Third
Edition Cameron Newham Digital Instant Download
Author(s): Cameron Newham
ISBN(s): 9780596009656, 0596009658
Edition: Third Edition
File Details: PDF, 1.63 MB
Year: 2005
Language: english
1
Learning the bash Shell,
3rd Edition
Table of Contents
2
Preface
bash Versions
Summary of bash Features
Intended Audience
Code Examples
Chapter Summary
Conventions Used in This Handbook
We'd Like to Hear from You
Using Code Examples
Safari Enabled
Acknowledgments for the First Edition
Acknowledgments for the Second Edition
Acknowledgments for the Third Edition
1. bash Basics
3
1.1. What Is a Shell?
1.2. Scope of This Book
1.3. History of UNIX Shells
1.3.1. The Bourne Again Shell
1.3.2. Features of bash
1.6. Files
1.6.1. Directories
1.6.2. Filenames, Wildcards, and Pathname
Expansion
1.6.3. Brace Expansion
4
1.10. Help
2. Command-Line Editing
2.1. Enabling Command-Line Editing
2.2. The History List
2.3. emacs Editing Mode
2.3.1. Basic Commands
2.3.2. Word Commands
2.3.3. Line Commands
2.3.4. Moving Around in the History List
2.3.5. Textual Completion
2.3.6. Miscellaneous Commands
5
3.1. The .bash_profile, .bash_logout, and .bashrc
Files
3.2. Aliases
3.3. Options
3.3.1. shopt
6
4.1. Shell Scripts and Functions
4.1.1. Functions
5. Flow Control
5.1. if/else
5.1.1. Exit Status
5.1.2. Return
5.1.3. Combinations of Exit Statuses
5.1.4. Condition Tests
5.1.5. Integer Conditionals
5.2. for
5.3. case
5.4. select
5.5. while and until
7
6.1. Command-Line Options
6.1.1. shift
6.1.2. Options with Arguments
6.1.3. getopts
6.4. Arrays
8. Process Handling
8
8.1. Process IDs and Job Numbers
8.2. Job Control
8.2.1. Foreground and Background
8.2.2. Suspending a Job
8.3. Signals
8.3.1. Control-Key Signals
8.3.2. kill
8.3.3. ps
8.4. trap
8.4.1. Traps and Functions
8.4.2. Process ID Variables and Temporary
Files
8.4.3. Ignoring Signals
8.4.4. disown
8.4.5. Resetting Traps
8.5. Coroutines
8.5.1. wait
8.5.2. Advantages and Disadvantages of
Coroutines
8.5.3. Parallelization
8.6. Subshells
8.6.1. Subshell Inheritance
8.6.2. Nested Subshells
9
9.1. Basic Debugging Aids
9.1.1. Set Options
9.1.2. Fake Signals
9.1.3. Debugging Variables
10
11.1. What's That Do?
11.1.1. Comments
11.1.2. Variables and Constants
11.2. Starting Up
11.3. Potential Problems
11.4. Don't Use bash
A. Related Shells
11
A.1. The Bourne Shell
A.2. The IEEE 1003.2 POSIX Shell Standard
A.3. The Korn Shell
A.4. pdksh
A.5. zsh
A.6. Shell Clones and Unix-like Platforms
A.6.1. Cygwin
A.6.2. DJGPP
A.6.3. MKS Toolkit
A.6.4. AT&T UWIN
B. Reference Lists
B.1. Invocation
B.2. Prompt String Customizations
B.3. Built-In Commands and Reserved Words
B.4. Built-In Shell Variables
B.5. Test Operators
B.6. set Options
B.7. shopt Options
B.8. I/O Redirection
B.9. emacs Mode Commands
B.10. vi Control Mode Commands
C. Loadable Built-Ins
D. Programmable Completion
12
Learning the bash Shell,
3rd Edition
Cameron Newham
Copyright © 2009 O'Reilly Media, Inc.
13
Preface
The first thing users of the UNIX or Linux operating
systems come face to face with is the shell. "Shell" is the
UNIX term for a user interface to the system—something
that lets you communicate with the computer via the
keyboard and the display. Shells are just separate
programs that encapsulate the system, and, as such, there
are many to choose from.
14
bash Versions
This book is relevant to all versions of bash, although
older versions lack some of the features of the most
recent version.[1] You can easily find out which version
you are using by typing echo $BASH_VERSION. The
earliest public version of bash was 1.0, and the most
recent is 3.0 (released in July 2004). If you have an older
version, you might like to upgrade to the latest one.
Chapter 12 shows you how to go about it.
[1]
Throughout this book we have clearly marked with
footnotes the features that are not present in the earlier
versions.
15
Summary of bash
Features
bash is a backward-compatible evolutionary successor to
the Bourne shell that includes most of the C shell's major
advantages as well as features from the Korn shell and a
few new features of its own. Features appropriated from
the C shell include:
16
• Command-line editing, allowing you to use vi- or
emacs-style editing commands on your command
lines.
17
Intended Audience
This book is designed to address casual UNIX and Linux
users who are just above the "raw beginner" level. You
should be familiar with the process of logging in, entering
commands, and doing simple things with files. Although
Chapter 1 reviews concepts such as the tree-like file and
directory scheme, you may find that it moves too quickly
if you're a complete neophyte. In that case, we
recommend the O'Reilly handbook, Learning the UNIX
Operating System, by Jerry Peek, Grace Todino, and John
Strang.
18
commands during a login session) and shell
programming. We see shell programming as a natural,
inevitable outgrowth of increasing experience as a user.
19
Code Examples
This book is full of examples of shell commands and
programs designed to be useful in your everyday life as a
user, not just to illustrate the feature being explained. In
Chapter 4 and onwards, we include various programming
problems, which we call tasks, that illustrate particular
shell programming concepts. Some tasks have solutions
that are refined in subsequent chapters. The later chapters
also include programming exercises, many of which build
on the tasks in the chapter.
Feel free to use any code you see in this book and to pass
it along to friends and colleagues. We especially
encourage you to modify and enhance it yourself.
#!/bin/bash
20
Chapter Summary
If you want to investigate specific topics rather than read
the entire book through, here is a chapter-by-chapter
summary:
21
Chapter 5 continues the discussion of shell programming
by describing command exit status, conditional
expressions, and the shell's flow-control structures: if,
for, case, select, while, and until.
22
Chapter 11 discusses ways to make bash scripts more
maintainable.
23
Conventions Used in
This Handbook
We leave it as understood that when you enter a shell
command, you press RETURN at the end. RETURN is
labeled ENTER on some keyboards.
Italic
Used for UNIX filenames, commands not built into
the shell (which are files anyway), and shell
functions. Italic is also used for dummy parameters
that should be replaced with an actual value, to
distinguish the vi and emacs programs from their
bash modes, and to highlight special terms the first
time they are defined.
24
Bold
Used for bash built-in commands, aliases, variables,
and options, as well as command lines when they are
within regular text. Bold is used for all elements
typed in by the user within regular text.
Constant Width
Used in examples to show the contents of files or the
output from commands.
Constant Bold
Used in examples to show interaction between the
user and the shell; any text the user types in is shown
in Constant Bold. For example:$ pwd/home/
cam/adventure/carrol $
Constant Italic
Used in displayed command lines for dummy
parameters that should be replaced with an actual
value.
Square Brackets
Used in Chapter 2 to show the position of the cursor
on the command line being edited. For
example:grep -l Alice < ~cam/book/
[a]iw
25
We use UNIX as a shorthand for "UNIX and Linux."
Purists will correctly insist that Linux is not
UNIX—but as far as this book is concerned, they
behave identically.
26
We'd Like to Hear from
You
Please address comments and questions concerning this
book to the publisher:
http://www.oreilly.com/catalog/bash3
To comment or ask technical questions about this book,
send email to:
[email protected]
For more information about our books, conferences,
Resource Centers, and the O'Reilly Network, see our web
site at:
http://www.oreilly.com
27
Using Code Examples
This book is here to help you get your job done. In
general, you may use the code in this book in your
programs and documentation. You do not need to contact
us for permission unless you're reproducing a significant
portion of the code. For example, writing a program that
uses several chunks of code from this book does not
require permission. Selling or distributing a CD-ROM of
examples from O'Reilly books does require permission.
Answering a question by citing this book and quoting
example code does not require permission. Incorporating
a significant amount of example code from this book into
your product's documentation does require permission.
28
Safari Enabled
29
Acknowledgments for
the First Edition
This project has been an interesting experience and
wouldn't have been possible without the help of a number
of people. Firstly, I'd like to thank Brian Fox and Chet
Ramey for creating bash and making it the polished
product it is today. Thanks also to Chet Ramey for
promptly answering all of my questions on bash and
pointing out my errors.
30
Reynolds, Bill Rosenblatt, and Norm Walsh for taking
time out to go through the manuscript.
31
Acknowledgments for
the Second Edition
Thanks to all the people at O'Reilly. Gigi Estabrook was
the editor for the second edition. Nicole Gipson Arigo
was the production editor and project manager. Nancy
Wolfe Kotary and Ellie Fountain Maden performed
quality control checks. Seth Maislin wrote the index. Edie
Freedman designed the cover, and Nancy Priest designed
the interior format of the book. Lenny Muellner
implemented the format in troff. Robert Romano updated
the illustrations for the second edition.
32
Acknowledgments for
the Third Edition
Thanks to the production people at O'Reilly and to the
indexer.
33
Chapter 1. bash Basics
Since the early 1970s, when it was first created, the
UNIX operating system has become more and more
popular. During this time it has branched out into
different versions, and taken on such names as Ultrix,
AIX, Xenix, SunOS, and Linux. Starting on
minicomputers and mainframes, it has moved onto
desktop workstations and even personal computers used
at work and home. No longer a system used only by
academics and computing wizards at universities and
research centers, UNIX is used in many businesses,
schools, and homes. As time goes on, more people will
come into contact with UNIX.
34
Figure 1-1 shows the relationship between user, shell, and
operating system.
35
What Is a Shell?
The shell's job, then, is to translate the user's command
lines into operating system instructions. For example,
consider this command line:
36
Of course, each of these steps really involves several
substeps, each of which includes a particular instruction
to the underlying operating system.
37
Scope of This Book
In this book you will learn about bash, which is one of
the most recent and powerful of the major UNIX shells.
There are two ways to use bash: as a user interface and as
a programming environment.
This chapter and the next cover interactive use. These two
chapters should give you enough background to use the
shell confidently and productively for most of your
everyday tasks.
After you have been using the shell for a while, you will
undoubtedly find certain characteristics of your
environment (the shell's "look and feel") that you would
like to change, and tasks that you would like to automate.
Chapter 3 shows several ways of doing this.
You'll learn a lot about bash in this book; you'll also learn
about UNIX utilities and the way the UNIX operating
38
system works in general. It's possible to become a
virtuoso shell programmer without any previous
programming experience. At the same time, we've
carefully avoided going into excessive detail about UNIX
internals. We maintain that you shouldn't have to be an
internals expert to use and program the shell effectively,
and we won't dwell on the few shell features that are
intended specifically for low-level systems programmers.
39
History of UNIX Shells
The independence of the shell from the UNIX operating
system per se has led to the development of dozens of
shells throughout UNIX history—although only a few
have achieved widespread use.
The first major shell was the Bourne shell (named after its
inventor, Steven Bourne); it was included in the first
popular version of UNIX, Version 7, starting in 1979.
The Bourne shell is known on the system as sh. Although
UNIX has gone through many, many changes, the Bourne
shell is still popular and essentially unchanged. Several
UNIX utilities and administration features depend on it.
40
Exploring the Variety of Random
Documents with Different Content
CHAPITRE DEUXIÈME
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com