Networking Chapter 6 Homework Use Example Show How Use For Loop Through Range Values3 Use The

subject Type Homework Help
subject Pages 9
subject Words 2834
subject Authors Michael Palmer

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
A Guide to Unix Using Linux, Fourth Edition 6-1
Chapter 6
Introduction to Shell Script Programming
At a Glance
Instructor’s Manual Table of Contents
Overview
Objectives
Teaching Tips
Quick Quizzes
Class Discussion Topics
Additional Projects
Additional Resources
Key Terms
Technical Notes for Hands-On Projects
page-pf2
A Guide to Unix Using Linux, Fourth Edition 6-2
Lecture Notes
Overview
The focus of this chapter is to develop shell script programming skills and to learn how to
build a menu-based application. Students begin by getting an overview of the application
they will build and of the program development cycle. Next, they learn about shell script
programming tools that include using variables, operators, and logic structures. Finally, in
the Hands-On Projects, they put to work what they’ve learned by building a menu-based
application.
Employ shell scripting to create a menu
Use commands to help debug shell scripts
Explain ways to customize your personal environment
Use the trap command
Develop a menu-based application
b. Begin the design process. Explain that in this step, you create file formats,
screen layouts, and algorithms.
c. Write the actual code. Note that the code must be tested and debugged.
page-pf3
A Guide to Unix Using Linux, Fourth Edition 6-3
Teaching
Tip
“Usage of the term ‘bug’ to describe inexplicable defects has been a part of
engineering jargon for many decades and predates computers and computer
software. It may have originally been used in hardware engineering to describe
‘mechanical malfunctions’.”
Reference: http://en.wikipedia.org/wiki/Computer_bug
Teaching
Tip
such as an invalid memory location specified in the program code. Logic errors
cause the program to produce invalid results because of problems such as flawed
mathematical statements.
way. After prototype is approved, script can be rewritten to run faster using a compiled
language.
Using Comments
1. Show a shell script in class and use it to explain the importance of adding expository
comments to a file.
page-pf4
page-pf5
A Guide to Unix Using Linux, Fourth Edition 6-5
c. To reference a variable, use a $ in front of it or enclose it in { }.
d. Use [ ] to refer to a specific value in an array.
e. Export a shell variable to make the variable available to other scripts.
f. To make a shell variable read-only: readonly fname.
2. Provide some guidelines for naming shell variables:
a. Avoid using dollar sign in variable names.
b. Use descriptive names.
c. Use capitalization appropriately and consistently.
d. If a variable name is to consist of two or more words, use underscores between
the words.
b. Evaluating operators
c. Arithmetic and relational operators
d. Redirection operators
Tip
Teaching
Tip
Note that on many standard keyboards, the key for the back quote operator is
located in the upper-left corner under the Esc key and is combined with the tilde
(~) on that key.
Evaluating Operators
1. Provide examples that illustrate how to use echo to display the contents of a variable.
page-pf6
A Guide to Unix Using Linux, Fourth Edition 6-6
Arithmetic and Relational Operators
1. Use Table 6-3 to discuss the most common shell arithmetic and relational operators.
2. Note that the usual mathematical and division precedence rules apply when using
arithmetic operators.
Teaching
Tip
You can find a table of the usual mathematical precedence rules at:
http://en.wikipedia.org/wiki/Order_of_operations.
3. Use Figure 6-3 to show how to store the result of a mathematical operation in a
variable, using the let command. Describe the syntax of let.
option to prevent a file from being overwritten (when using the > redirection operator).
2. Describe the syntax of the set command.
page-pf7
A Guide to Unix Using Linux, Fourth Edition 6-7
Teaching
Tip
Note that to save time and automatically export all shell script variables that have
been defined, use set with the -a option.
Teaching
Tip
current working directory is temporarily stored as part of your path only for the
duration of your login session.
Teaching
Tip
For a good explanation on the use of wildcard characters, read “How to use
wildcards, by The Linux Information Project (LINFO)”:
www.linfo.org/wildcard.html.
Shell Logic Structures
1. Note that the four basic logic structures needed for program development are:
a. Sequential logic
b. Decision logic
page-pf8
A Guide to Unix Using Linux, Fourth Edition 6-8
c. Looping logic
d. Case logic
2. Use the sample script provided in the book to explain the use of sequential logic.
2. Use an example to show how the case structure is useful for creating menus.
Quick Quiz 2
1. You can use the ____________________ command with the -o noclobber option to
prevent a file from being overwritten when using the > redirection operator.
Answer: set
page-pf9
A Guide to Unix Using Linux, Fourth Edition 6-9
2. Wildcard characters are also known as ____________________ characters.
2. Use one or more examples to show how to use this command.
page-pfa
A Guide to Unix Using Linux, Fourth Edition 6-10
Teaching
Tip
For a detailed description on the use of the trap command, visit
www.freeos.com/guides/lsst/ch04sec12.html.
Putting it All Together in an Application
1. In this chapter, students learned how to:
a. Assign and manage variables.
b. Use shell operators.
c. Employ shell logic structures.
d. Use additional wildcard characters.
e. Use tput for screen initialization and text placement.
f. Use trap to clean up temporary files.
Quick Quiz 3
1. The ____________________ command enables you to initialize the terminal display or
terminal window, to place text and prompts in desired locations, and to respond to what
the user selects from the menu.
4. ____________________ is a command in the Bash shell that is used to execute another
command when a specific signal is received.
Answer: trap
Class Discussion Topics
1. Some students may have had previous experience running scripts even if they have not
done any script programming. Ask them to describe the types and functionality of the
scripts they have worked with.
page-pfb
2. Ask your students to review the sample .bashrc file available at
http://tldp.org/LDP/abs/html/sample-bashrc.html and then compile a list of the five
customizations they found most useful.
Additional Resources
1. Scripting Language:
algorithm A sequence of instructions, programming code, or commands that results
in a program or that can be used as part of a program.
alias A name that represents a command. Aliases are helpful in simplifying and
automating frequently used commands.
arithmetic operator A character that represents a mathematical activity. Arithmetic
operators include + (addition), - (subtraction), * (multiplication), and / (division).
branch instruction An instruction that tells a program to go to a different section of
code.
case logic One of the four basic shell logic structures employed in program
development. Using case logic, a program can perform one of many actions, depending
on the value of a variable and matching results to a test. It is often used when there is a
list of several choices.
page-pfc
A Guide to Unix Using Linux, Fourth Edition 6-12
compiler A program that reads the lines of code in a source file, converts them to
machine-language instructions, or calls the assembler to convert them into object code,
and creates a machine-language file.
configuration variable A variable that stores information about the operating
system and does not change the value.
control structures See logic structures.
debugging The process of going through program code to locate errors and then fix
them.
decision logic One of the four basic shell logic structures used in program
development. In decision logic, commands execute only if a certain condition exists.
displaying the contents.
glob A character used to find or match file names; similar to a wildcard. Glob
characters are part of glob patterns.
glob pattern A combination of glob characters used to find or match multiple file
names.
high-level language A computer language that uses English-like expressions.
COBOL, Visual Basic (VB), C, and C++ are high-level languages.
interpreter A UNIX/Linux shell feature that reads statements in a program file,
login script A script that runs just after you log in to your account.
looping logic One of the four basic shell logic structures used in program
development. In looping logic, a control structure (or loop) repeats until some specific
condition exists or some action occurs.
nest When creating program code, a practice of layering statements at two or more
levels under an original statement structure.
operand The variable name that appears to the left of an operator or the variable
value that appears to the right of an operator. For example, in NAME=Becky, NAME is
the variable name, = is the operator, and Becky is the variable value. Note that no
spaces separate the operator and operands.
PATH variable A path identifier that provides a list of directory locations where
UNIX/Linux look for executable programs.
program development cycle The process of developing a program, which includes
(1) creating program specifications, (2) the design process, (3) writing code, (4) testing,
(5) debugging, and (6) correcting errors.
prototype A running model, which lets programmers review a program before
committing to its design.
page-pfd
A Guide to Unix Using Linux, Fourth Edition 6-13
redirection operator An operator or symbol that changes the input or output data
stream from its default direction, such as using > to redirect output to a file instead of to
the screen.
relational operator Compares the relationship between two values or arguments,
such as greater than (>), less than (<), equal to (=), and others.
sequential logic One of four basic logic structures used for program development. In
sequential logic, commands execute in the order they appear in the program, except
when a branch instruction changes the flow of execution.
shell script operator The symbols used with shell scripts that define and evaluate
information, that perform arithmetic actions, and that perform redirection or piping

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.