Shell Script Assignments
In assignments you will be writing shell programs, commonly called shell scripts. The first section this
handout is a suggested method of creating shell scripts. The second section discusses
Variables and Arithmetic
When you create a variable it is local to the current shell. If you start a new process, the new
process does not know the variable even exists.
A subset of your variables are copied to child processes when they are started. These
GENERAL NOTES FOR 160B
Shell Script Assignments
In assignments you will be writing shell programs, commonly called
shell scripts. This document is broken up into three sections.
1. Guidelines and suggested method of creating shell scripts.
2. Goals and fe
Permissions on Unix are simple. There are just three:
r - read (you can read the file's contents)
w write (you can update the file's contents)
x execute (you can attempt to execute the file as a program)
There are three sets of these three
Exercises 4 - Command Substitution and Arithmetic
Information to help you with these exercises.
The output of the date command (with a single blank between the fields) is $ date
Fri Nov 30 17:48:16 PST 2003
Note the columns will stay the same but there wi
This section contains examples of Scripting Basics 1. Most of the answers are at the end of the
section, with some comments. Some of them require you to actually test the solutions on your
own. These examples are not meant to replace the Exercise
Commands Files vs. Shell Scripts
Your book refers to shell scripts and commands files interchangeably. We will be making a
distinction in class. Both refer to a file of Unix commands. Whether we refer to them as a
commands file or as a shell script depend
Internal Documentation Guidelines. Here is what to include in your assignments:
1. Comments at the beginning of the script:
a first line that indicates which Unix shell to use for this script
the script name and its purpose.
any arguments and what t
In these exercises you will investigate some issues with variables, including local vs. Environme
nt variables, standard shell variables, and the $cfw_ operator.
You will also demonstrate the difference between executing a shell script
The book's treatment of command substitution is quite good. However, there are a few issues we
would like to reiterate:
Command substitution allows you to embed one Unix command on the commandline of another.
The embedded command is r
EXERCISES 1 - ARGUMENTS
These questions practice arguments and if statements. You should begin by looking at the files
beneath the samples/args and samples/iftest directories beneath the class public work area.
What does the f
This exercise set reviews some two basic Unix skills: wildcards and text filters. Only a few exercises are
given on each topic: if a topic is difficult, you should get more practice by returning to
Exercises: Command Substitution and Arithmetic
Information to help you with these exercises The output of the date command (with a single blank between the fields) is $ date Fri Nov 30 17:48:16 PST 2003 Note the column
These questions practice arguments and if statements. You should begin by looking at the files beneath the samples/args and samples/iftest directories beneath the class public work area. 1. What does the following command d