Learning the bash Shell: Unix Shell Programming

( 8 )

Overview

O'Reilly's bestselling book on Linux's bash shell is at it again. Now that Linux is an established player both as a server and on the desktop Learning the bash Shell has been updated and refreshed to account for all the latest changes. Indeed, this third edition serves as the most valuable guide yet to the bash shell.As any good programmer knows, the first thing users of the Linux operating system come face to face with is the shell the UNIX term for a user interface to the system. In other words, it's what lets ...

See more details below
Paperback (Third Edition)
$23.80
BN.com price
(Save 31%)$34.95 List Price

Pick Up In Store

Reserve and pick up in 60 minutes at your local store

Other sellers (Paperback)
  • All (15) from $18.66   
  • New (7) from $19.40   
  • Used (8) from $18.60   
Learning the bash Shell: Unix Shell Programming

Available on NOOK devices and apps  
  • NOOK Devices
  • NOOK HD/HD+ Tablet
  • NOOK
  • NOOK Color
  • NOOK Tablet
  • Tablet/Phone
  • NOOK for Windows 8 Tablet
  • NOOK for iOS
  • NOOK for Android
  • NOOK Kids for iPad
  • PC/Mac
  • NOOK for Windows 8
  • NOOK for PC
  • NOOK for Mac
  • NOOK Study
  • NOOK for Web

Want a NOOK? Explore Now

NOOK Book (eBook)
$15.49
BN.com price
(Save 44%)$27.99 List Price

Overview

O'Reilly's bestselling book on Linux's bash shell is at it again. Now that Linux is an established player both as a server and on the desktop Learning the bash Shell has been updated and refreshed to account for all the latest changes. Indeed, this third edition serves as the most valuable guide yet to the bash shell.As any good programmer knows, the first thing users of the Linux operating system come face to face with is the shell the UNIX term for a user interface to the system. In other words, it's what lets you communicate with the computer via the keyboard and display. Mastering the bash shell might sound fairly simple but it isn't. In truth, there are many complexities that need careful explanation, which is just what Learning the bash Shell provides.If you are new to shell programming, the book provides an excellent introduction, covering everything from the most basic to the most advanced features. And if you've been writing shell scripts for years, it offers a great way to find out what the new shell offers. Learning the bash Shell is also full of practical examples of shell commands and programs that will make everyday use of Linux that much easier. With this book, programmers will learn:

  • How to install bash as your login shell
  • The basics of interactive shell use, including UNIX file and directory structures, standard I/O, and background jobs
  • Command line editing, history substitution, and key bindings
  • How to customize your shell environment without programming
  • The nuts and bolts of basic shell programming, flow control structures, command-line options and typed variables
  • Process handling, from job control to processes, coroutines and subshells
  • Debugging techniques, such as trace and verbose modes
  • Techniques for implementing system-wide shell customization and features related to system security


This is the definitive guide to the "Bourne Again Shell" (bash). Bash is a modern general purpose UNIX and LINUX shell that incorporates elements of the C and Korn shells. It covers the new commands and features of bash version 2.0, and emphasizes POSIX compliance in POSIX 2.0 mode. This publication is designed for those who have just starting shell programming. The authors guide you from bash installation and command line editing through customization, flow control, process handling and debugging. Along the way, you learn about shell scripts, I/O and command line processing, positional parameters, properties and shell administration. The new features for bash v2.0 are command line editing, bindings, arrays, dynamic loading and integrated programming.

Read More Show Less

Editorial Reviews

From Barnes & Noble

Fatbrain Review

This is the definitive guide to the "Bourne Again Shell" (bash). Bash is a modern general purpose UNIX and LINUX shell that incorporates elements of the C and Korn shells. It covers the new commands and features of bash version 2.0, and emphasizes POSIX compliance in POSIX 2.0 mode. This publication is designed for those who have just starting shell programming. The authors guide you from bash installation and command line editing through customization, flow control, process handling and debugging. Along the way, you learn about shell scripts, I/O and command line processing, positional parameters, properties and shell administration. The new features for bash v2.0 are command line editing, bindings, arrays, dynamic loading and integrated programming.
Booknews
A guide to bash, a default shell, or command interpreter, for Linux, a free UNIX-like operating system for PCs. Comprehensively covers bash's features for both interactive use and programming. Annotation c. Book News, Inc., Portland, OR (booknews.com)
Read More Show Less

Product Details

  • ISBN-13: 9780596009656
  • Publisher: O'Reilly Media, Incorporated
  • Publication date: 4/5/2005
  • Series: In a Nutshell (O'Reilly) Series
  • Edition description: Third Edition
  • Edition number: 3
  • Pages: 354
  • Sales rank: 325,699
  • Product dimensions: 7.00 (w) x 9.20 (h) x 0.90 (d)

Meet the Author

Cameron Newham lives in Perth, Western Australia. After completing a Bachelor of Science majoring in information technology and geography at the University of Western Australia, Cameron joined Universal Defence Systems (later to become Australian Defence Industries) as a software engineer. He has been with ADI for six years, working on various aspects of command and control systems. In his spare time Cameron can be found surfing the Internet, ballroom dancing, or driving his sports car. He also has more than a passing interest in space science, 3D graphics, synthesiser music, and Depeche Mode.

Read More Show Less

Read an Excerpt


From Chapter 1: bash Basics

...Pipelines

It is also possible to redirect the output of a command into the standard input of another command instead of a file. The construct that does this is called the pipe, notated as |. A command line that includes two or more commands connected with pipes is called a pipeline.

Pipes are very often used with the more command, which works just like cat except that it prints its output screen by screen, pausing for the user to type SPACE (next screen), RETURN (next line), or other commands. If you're in a directory with a large number of files and you want to see details about them, Is -1 | more will give you a detailed listing a screen at a time.

Pipelines can get very complex, and they can also be combined with other I/O directors. To see a sorted listing of the file cheshire a screen at a time, type sort < cheshire | more. To print it instead of viewing it on your terminal, type sort < cheshire | lp.

Here's a more complicated example. The file /etc/passwd stores information about users' accounts on a UNIX system. Each line in the file contains a user's login name, user ID number, encrypted password, home directory, login shell, and other information. The first field of each line is the login name; fields are separated by colons (:). A sample line might look like this:

cam:LM1c7GhNesD4GhF3iEHrHrH4FeCKB/:501:100:Cameron Newham:/home/cam:/bin/bash

To get a sorted listing of all users on the system, type:

$ cut -d: -f1 < /etc/passwd | sort

(Actually, you can omit the <, since cut accepts input filenamearguments.) The cut command extracts the first field (-f1), where fields are separated by colons (-d:), from the input. The entire pipeline will print a list that looks like this:

adm
bin
cam
daemon
davidgc
ftp
games
gonzo
...

If you want to send the list directly to the printer (instead of your screen), you can extend the pipeline like this:

$ cut -d: -f1 < /etc/passwd | sort | lp

Now you should see how I/O directors and pipelines support the UNIX building block philosophy. The notation is extremely terse and powerful. Just as important, the pipe concept eliminates the need for messy temporary files to store command output before it is fed into other commands.

For example, do the same sort of thing as the above command line on other operating systems (assuming that equivalent utilities are available...), you need three commands. On DEC's VAX/VMS system, they might look like this:

$ cur [etc]passwd /d=":" /f=1 /out=temp1
$ sort temp1 /out=temp2
$ print temp2
$ delete temp1 temp2

After sufficient practice, you will find yourself routinely typing in powerful command pipelines that do in one line what it would take several commands (and temporary files) in other operating systems to accomplish.

Background Jobs

Pipes are actually a special case of a more general feature: doing more than one thing at a time. This is a capability that many other commercial operating systems don't have, because of the rigid limits that they tend to impose upon users. UNIX, on the other hand, was developed in a research lab and meant for internal use, so it does relatively little to impose limits on the resources available to users on a computer--as usual, leaning towards uncluttered simplicity rather than overcomplexity.

"Doing more than one thing at a time" means running more than one program at the same time. You do this when you invoke a pipeline; you can also do it by logging on to a UNIX system as many times simultaneously as you wish. (If you try that on an IBM's VM/CMS system, for example, you will get an obnoxious "already logged in" message.)

The shell also lets you run more than one command at a time during a single login session. Normally, when you type a command and hit RETURN, the shell will let the command have control of your terminal until it is done; you can't type in further commands until the first one is done. But if you want to run a command that does not require user input and you want to do other things while the command is running, put an ampersand (&) after the command.

This is called running the command in the background, and a command that runs in this way is called a background job; by contrast, a job run the normal way is called a foreground job. When you start a background job, you get your shell prompt back immediately, enabling you to enter other commands.

The most obvious use for background jobs is programs that take a long time to run, such as sort or uncompress on large files. For example, assume you just got an enormous compressed file loaded into your directory from magnetic tape.* Let's say the file is gcc.tar.z, which is a compressed archive file that contains well over 10 MB of source code files.

Type uncompress gcc.tar & (you can omit the .Z), and the system will start a job in the background that uncompresses the data "in place" and ends up with the file gcc.tar. Right after you type the command, you will see a line like this:

[1] 175

followed by your shell prompt, meaning that you can enter other commands. Those numbers give you ways of referring to your background job; Chapter 8, explains them in detail.

You can check on background jobs with the command jobs. For each background job, jobs prints a line similar to the above but with an indication of the job's status:

[1]+ Running uncompress gcc.tar &

When the job finishes, you will see a message like this right before your shell prompt:

[1]+ Done uncompress gcc.tar

The message changes if your background job terminated with an error; again, see Chapter 8 for details...

Read More Show Less

Table of Contents

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;
Chapter 1: bash Basics;
1.1 What Is a Shell?;
1.2 Scope of This Book;
1.3 History of UNIX Shells;
1.4 Getting bash;
1.5 Interactive Shell Use;
1.6 Files;
1.7 Input and Output;
1.8 Background Jobs;
1.9 Special Characters and Quoting;
1.10 Help;
Chapter 2: Command-Line Editing;
2.1 Enabling Command-Line Editing;
2.2 The History List;
2.3 emacs Editing Mode;
2.4 vi Editing Mode;
2.5 The fc Command;
2.6 History Expansion;
2.7 readline;
2.8 Keyboard Habits;
Chapter 3: Customizing Your Environment;
3.1 The .bash_profile, .bash_logout, and .bashrc Files;
3.2 Aliases;
3.3 Options;
3.4 Shell Variables;
3.5 Customization and Subprocesses;
3.6 Customization Hints;
Chapter 4: Basic Shell Programming;
4.1 Shell Scripts and Functions;
4.2 Shell Variables;
4.3 String Operators;
4.4 Command Substitution;
4.5 Advanced Examples: pushd and popd;
Chapter 5: Flow Control;
5.1 if/else;
5.2 for;
5.3 case;
5.4 select;
5.5 while and until;
Chapter 6: Command-Line Options and Typed Variables;
6.1 Command-Line Options;
6.2 Typed Variables;
6.3 Integer Variables and Arithmetic;
6.4 Arrays;
Chapter 7: Input/Output and Command-Line Processing;
7.1 I/O Redirectors;
7.2 String I/O;
7.3 Command-Line Processing;
Chapter 8: Process Handling;
8.1 Process IDs and Job Numbers;
8.2 Job Control;
8.3 Signals;
8.4 trap;
8.5 Coroutines;
8.6 Subshells;
8.7 Process Substitution;
Chapter 9: Debugging Shell Programs;
9.1 Basic Debugging Aids;
9.2 A bash Debugger;
Chapter 10: bash Administration;
10.1 Installing bash as the Standard Shell;
10.2 Environment Customization;
10.3 System Security Features;
Chapter 11: Shell Scripting;
11.1 What's That Do?;
11.2 Starting Up;
11.3 Potential Problems;
11.4 Don't Use bash;
Chapter 12: bash for Your System;
12.1 Obtaining bash;
12.2 Unpacking the Archive;
12.3 What's in the Archive;
12.4 Who Do I Turn to?;
Appendix A: Related Shells;
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;
Appendix 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;
Appendix C: Loadable Built-Ins;
Appendix D: Programmable Completion;
Colophon;

Read More Show Less

Customer Reviews

Average Rating 4.5
( 8 )
Rating Distribution

5 Star

(5)

4 Star

(2)

3 Star

(1)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing all of 8 Customer Reviews
  • Anonymous

    Posted October 2, 2012

    Amy

    I live u too

    1 out of 2 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted April 21, 2005

    simple subject

    [A review of the THIRD EDITION 2005.] In the last 10 years, it appears that the shell wars in unix and linux have settled down. With bash being the clear favourite. So if you are going to invest your time learning any shell, perhaps you should go with bash and maybe use this book as a helper. It shows that script writing in bash is pretty simple. If you already know another shell, like csh or Korn, then the ideas carry over and so too would most of the syntax. Along the way, the book teaches you more about your operating system. Especially for managing processes/jobs. My background is as a programmer, so I've never been big on shells and their scripting. But others like you may hark from a sysadmin role and prefer shell activity.

    1 out of 1 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted October 4, 2012

    Damion

    Kate srry for being so harsh.

    0 out of 1 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted October 3, 2012

    Kate

    Next time label your house. Rides her seahorse away.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted March 30, 2009

    No text was provided for this review.

  • Anonymous

    Posted May 10, 2011

    No text was provided for this review.

  • Anonymous

    Posted June 23, 2011

    No text was provided for this review.

  • Anonymous

    Posted August 21, 2009

    No text was provided for this review.

Sort by: Showing all of 8 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)