Skip to Content
Classic Shell Scripting
book

Classic Shell Scripting

by Arnold Robbins, Nelson H. F. Beebe
May 2005
Intermediate to advanced
560 pages
15h 18m
English
O'Reilly Media, Inc.
Content preview from Classic Shell Scripting

Summary

Variables are necessary for any serious programming. Shell variables hold string values, and a large array of operators for use in ${ var...} lets you control the results of variable substitution.

The shell provides a number of special variables (those with nonalphanumeric names, such as $? and $!), that give you access to special information, such as command exit status. The shell also has a number of special variables with predefined meanings, such as PS1, the primary prompt string. The positional parameters and special variables $* and $@ give you access to the arguments used when a script (or function) was invoked. env, export, and readonly give you control over the environment.

Arithmetic expansion with $((...)) provides full arithmetic capabilities, using the same operators and precedence as in C.

A program's exit status is a small integer number that is made available to the invoker when the program is done. Shell scripts use the exit command for this, and shell functions use the return command. A shell script can get the exit status of the last command executed in the special variable $?.

The exit status is used for control-flow with the if, while, and until statements, and the !, && and || operators.

The test command, and its alias [...], test file attributes and string and numeric values, and are useful in if, while, and until statements.

The for loop provides a mechanism for looping over a supplied set of values, be they strings, filenames, or whatever else. while

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Complete Bash Shell Scripting

Complete Bash Shell Scripting

Narendra Kumar Reddy Polu
Linux Shell Scripting Cookbook - Third Edition

Linux Shell Scripting Cookbook - Third Edition

Clif Flynt, Sarath Lakshman, Shantanu Tushar

Publisher Resources

ISBN: 0596005954Errata Page