Creating a Shell Script

A shell script is nothing more than a list of commands for Unix to execute. To write a shell script, you’ll

1.
Open your favorite editor and start a script file.
2.
Start the shell script with #!/bin/sh.
3.
Add the shell script code one line at a time. This code will look strangely familiar— it’s similar to code you’ve already used in this book.
4.
Save and close the file.

In the following steps, we’ll show you how to try out this process by writing a script that prints three lines onscreen (Figure 10.1). Yeah, we know—whoopee!—but you have to start somewhere, and you can apply the same principles to other shell scripts you create.

Figure 10.1. You create shell scripts in an editor one line at a time.

Get Unix Third Edition: Visual Quickstart Guide 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.