Learning the bash Shell: Unix Shell Programming (In a Nut... and over 2 million other books are available for Amazon Kindle . Learn more


or
Sign in to turn on 1-Click ordering.
Trade in Yours
For a 3.50 Gift Card
Trade in
More Buying Choices
Have one to sell? Sell yours here
Sorry, this item is not available in
Image not available for
Colour:
Image not available

 
Start reading Learning the bash Shell on your Kindle in under a minute.

Don't have a Kindle? Get your Kindle here, or download a FREE Kindle Reading App.

Learning the bash Shell: Unix Shell Programming (In a Nutshell (O'Reilly)) [Paperback]

Cameron Newham
4.0 out of 5 stars  See all reviews (1 customer review)
RRP: 26.99
Price: 18.08 & FREE Delivery in the UK. Details
You Save: 8.91 (33%)
o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o
Only 12 left in stock (more on the way).
Dispatched from and sold by Amazon. Gift-wrap available.
Want it Wednesday, 23 April? Choose Express delivery at checkout. Details

Formats

Amazon Price New from Used from
Kindle Edition 10.50  
Paperback 18.08  
Amazon.co.uk Trade-In Store
Did you know you can use your mobile to trade in your unwanted books for an Amazon.co.uk Gift Card to spend on the things you want? Visit the Books Trade-In Store for more details or check out the Trade-In Amazon Mobile App Guidelines on how to trade in using a smartphone. Learn more.

Book Description

8 April 2005 In a Nutshell (O'Reilly)

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

Frequently Bought Together

Learning the bash Shell: Unix Shell Programming (In a Nutshell (O'Reilly)) + Classic Shell Scripting: Hidden Commands that Unlock the Power of Unix + bash Pocket Reference (Pocket Reference (O'Reilly))
Price For All Three: 44.32

Buy the selected items together


Product details

  • Paperback: 354 pages
  • Publisher: O'Reilly Media; 3 edition (8 April 2005)
  • Language: English
  • ISBN-10: 0596009658
  • ISBN-13: 978-0596009656
  • Product Dimensions: 23.4 x 17.8 x 2.3 cm
  • Average Customer Review: 4.0 out of 5 stars  See all reviews (1 customer review)
  • Amazon Bestsellers Rank: 92,914 in Books (See Top 100 in Books)
  • See Complete Table of Contents

Product Description

About 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.

Excerpt. © Reprinted by permission. All rights reserved.

CHAPTER 4 Basic Shell Programming

If you have become familiar with the customization techniques we presented in the previous chapter, you have probably run into various modifications to your environment that you want to make but can’t—yet. Shell programming makes these possible.

bash has some of the most advanced programming capabilities of any command interpreter of its type. Although its syntax is nowhere near as elegant or consistent as that of most conventional programming languages, its power and flexibility are comparable. In fact, bash can be used as a complete environment for writing software prototypes.

Some aspects of bash programming are really extensions of the customization techniques we have already seen, while others resemble traditional programming language features. We have structured this chapter so that if you aren’t a programmer, you can read this chapter and do quite a bit more than you could with the information in the previous chapter. Experience with a conventional programming language like Pascal or C is helpful (though not strictly necessary) for subsequent chapters. Throughout the rest of the book, we will encounter occasional programming problems, called tasks, whose solutions make use of the concepts we cover.

Shell Scripts and Functions

A script (a file that contains shell commands) is a shell program. Your .bash_profile and environment files, discussed in the previous chapter, are shell scripts.

You can create a script using the text editor of your choice. Once you have created one, there are two ways to run it. One, which we have already covered, is to type source scriptname. This causes the commands in the script to be read and run as if you typed them in.

The second way to run a script is simply to type its name and hit RETURN, just as if you were invoking a built-in command. This, of course, is the more convenient way. This method makes the script look just like any other UNIX command, and in fact several "regular" commands are implemented as shell scripts (i.e., not as programs originally written in C or some other language), including spell, man on some systems, and various commands for system administrators. The resulting lack of distinction between "user command files" and "built-in commands" is one factor in UNIX’s extensibility and, hence, its favored status among programmers.

You can run a script by typing its name only if the directory where the script is located is in your command search path, or . (the current directory) is part of your command search path, i.e., the script’s directory path (as discussed in Chapter 3). If these aren’t in your path, you must type ./scriptname, which is really the same thing as typing the script’s absolute pathname (see Chapter 1).

Before you can invoke the shell script by name, you must also give it "execute" permission. If you are familiar with the UNIX filesystem, you know that files have three types of permissions (read, write, and execute) and that those permissions apply to three categories of user (the file’s owner, a group of users, and everyone else). Normally, when you create a file with a text editor, the file is set up with read and write permission for you and read-only permission for everyone else.

Therefore you must give your script execute permission explicitly, by using the chmod command. The simplest way to do this is to type:

$ chmod +x scriptname

Your text editor will preserve this permission if you make subsequent changes to your script. If you don’t add execute permission to the script and you try to invoke it, the shell will print the message:

scriptname: Permission denied

But there is a more important difference between the two ways of running shell scripts. While using source causes the commands in the script to be run as if they were part of your login session, the "just the name" method causes the shell to do a series of things. First, it runs another copy of the shell as a subprocess; this is called a subshell. The subshell then takes commands from the script, runs them, and terminates, handing control back to the parent shell.

Figure 4-1 shows how the shell executes scripts. Assume you have a simple shell script called alice that contains the commands hatter and gryphon. In .a, typing source alice causes the two commands to run in the same shell, just as if you had typed them in by hand. .b shows what happens when you type just alice: the commands run in the subshell while the parent shell waits for the subshell to finish.

You may find it interesting to compare this with the situation in .c, which shows what happens when you type alice &. As you will recall from Chapter 1, the & makes the command run in the background, which is really just another term for "subprocess." It turns out that the only significant difference between .c and .b is that you have control of your terminal or workstation while the command runs — you need not wait until it finishes before you can enter further commands.

There are many ramifications to using subshells. An important one is that the exported environment variables that we saw in the last chapter (e.g., TERM, EDITOR, PWD) are known in subshells, whereas other shell variables (such as any that you define in your .bash_profile without an export statement) are not.

Other issues involving subshells are too complex to go into now; see Chapter 7 and Chapter 8 for more details about subshell I/O and process characteristics, respectively. For now, just bear in mind that a script normally runs in a subshell.


Inside This Book (Learn More)
Explore More
Concordance
Browse Sample Pages
Front Cover | Copyright | Table of Contents | Excerpt | Index | Back Cover
Search inside this book:

What Other Items Do Customers Buy After Viewing This Item?


Customer Reviews

5 star
0
3 star
0
2 star
0
1 star
0
4.0 out of 5 stars
4.0 out of 5 stars
Most Helpful Customer Reviews
1 of 1 people found the following review helpful
4.0 out of 5 stars Quite perfect!! 25 Dec 2012
Format:Paperback|Verified Purchase
I used this book to learn Bash language! It was very easy to read,but it's not for advanced student (also the title says this...). I appreciated it.
Comment | 
Was this review helpful to you?
Most Helpful Customer Reviews on Amazon.com (beta)
Amazon.com: 4.2 out of 5 stars  26 reviews
35 of 36 people found the following review helpful
4.0 out of 5 stars Strong, gently-paced intro 24 Oct 2006
By wiredweird - Published on Amazon.com
Format:Paperback|Verified Purchase
The bash shell is now the most common and featureful command shell in the Unix world. It's full capability certainly isn't obvious to a beginner facing a command prompt, but is well worth exploring. This book is a great place for the novice to start. The first chapter addresses the most fundamental question: just what is a command shell?

The ideal reader already knows at least the names of the emacs and vi editors. That much helps understand the many features and two distinct feature sets available for command line editing. I consider fancy command line editing over-rated for fluent typists, but it's there in the second chapter for all who want it and anyone can benefit from at least a little knowledge of it. After that successive chapters pull the reader deeper into the bash feature set: aliases and shell variables, scripting and shell programming, and debugging when the shell programs or functions go awry.

Since this book is aimed at the novice, Newham and Rosenblatt skip lightly over a few of the more advanced subjects. For example, exceptions and trap handling get only cursory treatment, since they get into deep weirdness very fast. The authors are honest about this shallow treatment, though, and give enough information for a novice to recognize the basics and look them up in more advanced references.

This is nicely organized for the self-taught student. As a result, it's not laid out as a programmer's reference manual - anyone who wants that kind of reference just isn't looking at the right book. For its intended reader, though, it's a great book. It gets readers off to a fast start, and lets them decide just how much they want to bite off at a time. I recommned it very highly.

//wiredweird
7 of 8 people found the following review helpful
2.0 out of 5 stars Confusing 11 Feb 2012
By Ian Belcher - Published on Amazon.com
Format:Paperback
I have been using UNIX for a few years, nothing too in depth, but I can get around. I recently went through the book Learning the UNIX Operating System, Fifth Edition without any trouble and then moved onto the book in question. Starting with the third chapter I felt completely lost and had no idea what the heck the author was talking about. The examples are vague and unhelpful. I kept reading, however, and into the fourth chapter the confusion persisted. Perhaps if the author decided to include some hands-on examples and/or exercises I might understand the concepts better.

I could see this being a worthwhile book if you know how to program already, but if you are just familiar with UNIX navigation, commands, (ie. anything in the Learning the UNIX Operating System, Fifth Edition book) then you might be out of luck.
3 of 3 people found the following review helpful
5.0 out of 5 stars Outstanding in every way 14 Jun 2008
By Jay Link - Published on Amazon.com
Format:Paperback
I first bought this book over 12 years ago, and I still use it as the standard by which other books are measured. It must be one of my top 5 favorite computer books, ever.

The author clearly understands the material, and makes it approachable, direct, and easy to learn without being too light or condescending. I wish the same could be said of Java books.

"Learning the bash Shell" is the right size and right price, too. Perfect in every way.

O'Reilly kind of took a turn for the worse in the late '90s / early 2000s, but this was originally published back when they were good the first time. (They've since recovered, IMO)

If you have need to learn the bash shell, you can't go wrong with this one.
2 of 2 people found the following review helpful
4.0 out of 5 stars Good chapter on debugging. 16 Nov 2006
By Computer_Geek - Published on Amazon.com
Format:Paperback
Good chapter on debugging. Good overview of the Bash shell, but I wish it had more examples. For a book with lots of examples, you might want to consider "Bash Shell: Essential Programs for Your Survival at Work" by Larry L. Smith.
1 of 1 people found the following review helpful
3.0 out of 5 stars While anyone will learn some new things, the entire approach of the 3rd edition was obsolete by the time of its 2005 publication 4 Jan 2014
By Christopher Culver - Published on Amazon.com
Format:Paperback
Cameron Newham's LEARNING THE BASH SHELL is an introduction to the command-line interface most commonly encountered today in server administration and in the terminal application of personal computers running Linux and Mac OS X. As I write this, the most recent edition is the 3rd, published in 2005, which describes bash 3.0. Newham explains such things as how programs communicate with the shell, keyboard navigation commands and shell customization. While he uses some of the old standard Unix programs (e.g. grep, sort) in examples, this is not a book about how to wield the power of Unix-like systems in general. Also, shell scripting is given only a brief mention, and those wanting to write powerful scripts will have to turn to another book (like O'Reilly's Classic Shell Scripting.

I have been using bash for nearly all file management and system administration tasks since 2002, and I still learned a few things here. However, this book is sorely in need of a new edition. The 3rd edition still assumes that the typical newcomer to bash is on a multi-user UNIX system, has access to a Postscript printer from the command line and a magnetic tape drive, and has probably used another shell like tcsh. Surely, even by the 3rd edition's publication date of 2005, most people interested in bash were people who had installed Linux on their personal computers. Also, bash is now at version 4.0, and readers would benefit from a small presentation of what has changed.
Were these reviews helpful?   Let us know
Search Customer Reviews
Only search this product's reviews
ARRAY(0xa54c70a8)

Customer Discussions

This product's forum
Discussion Replies Latest Post
No discussions yet

Ask questions, Share opinions, Gain insight
Start a new discussion
Topic:
First post:
Prompts for sign-in
 

Search Customer Discussions
Search all Amazon discussions
   


Look for similar items by category


Feedback