Contents

Acknowledgments

Introduction

Part One The Basics of Shell Scripting

Chapter 1 Scripting Quick Start and Review

Case Sensitivity

UNIX Special Characters

Shells

Shell Scripts

Functions

Running a Shell Script

Declare the Shell in the Shell Script

Comments and Style in Shell Scripts

Control Structures

if … then statement

if … then … else statement

if … then … elif … (else) statement

for … in statement

while statement

until statement

case statement

Using break, continue, exit, and return

Here Document

Shell Script Commands

Symbol Commands

Variables

Command-Line Arguments

shift Command

Special Parameters $* and $@

Special Parameter Definitions

Double Quotes, Forward Tics, and Back Tics

Using awk on Solaris

Using the echo Command Correctly

Math in a Shell Script

Operators

Built-In Mathematical Functions

File Permissions, suid and sgid Programs

chmod Command Syntax for Each Purpose

To Make a Script Executable

To Set a Program to Always Execute as the Owner

To Set a Program to Always Execute as a Member of the File Owner's Group

To Set a Program to Always Execute as Both the File Owner and the File Owner's Group

Running Commands on a Remote Host

Setting Traps

User-Information Commands

who Command

w Command

last Command

ps Command

Communicating with Users

Uppercase or Lowercase Text for Easy Testing

Check the Return Code

Time-Based Script Execution

Cron Tables

Cron Table Entry Syntax

at Command

Output Control

Silent Running

Using getopts to Parse Command-Line Arguments

Making a ...

Get Mastering UNIX® Shell Scripting: Bash, Bourne, and Korn Shell Scripting for Programmers, System Administrators, and UNIX Gurus, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.