Advanced Unix – Scripts Bourne

This document explains how to create and execute Bourne shell scripts. You will also learn about
shell builtins, input/output redirection, and quoting as well as the difference between interactive and subshell scripting.


1.1 Scripts

What is a script? A script is a set of commands, either in a ?le, or typed in at the command line, that per-
form multiple operations on a ?le or ?les. Another term for scripts that might be familiar to you is a
How do they work? To run a ?le as a script, the ?le must have the execution bit set. As you’ll recall from
the Unix I course, this means the ?le looks like this when you look at it:

As an alternative to setting the execution bits on a ?le and then running that ?le directly, it is also possi-
ble to read commands from a non-executable ?le into the current shell. Because this runs the current
shell as an interpreter on the ?le being read, it should be used very carefully, since any environment
variables set or changed in the script will be altered in the current shell. As a result, it is safer to run the
script in its own subshell.


This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s