Networking Chapter 7 Homework Algorithm Place The Cursor1 Use The Example Provided The Book Show How

subject Type Homework Help
subject Pages 9
subject Words 2146
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 7-1
Chapter 7
Advanced Shell Programming
At a Glance
Instructor’s Manual Table of Contents
Overview
Objectives
Teaching Tips
Quick Quizzes
page-pf2
A Guide to Unix Using Linux, Fourth Edition 7-2
Lecture Notes
Overview
Chapter 7 covers advanced shell programming techniques. The chapter begins by
introducing flowchart and pseudocode design and analysis tools. Students learn how to
ensure that a script is employing the correct shell, and how to use the test and tr
commands. Several useful configuration as well as programming and debugging tips are
provided as well.
Chapter Objectives
Perform program design and analysis using flowcharts and pseudocode
Use techniques to ensure a script is employing the correct shell
Set the default shell
Configure Bash login and logout scripts
Set defaults for the vi editor
Use the test command for programming functions
Teaching Tips
Understanding Program Design and Analysis
2. Note that two popular and proven analysis tools are flowcharts and pseudocode.
Flowcharting
2. Use Figure 7-2 to describe the role of each of the standard flowchart symbols.
page-pf3
A Guide to Unix Using Linux, Fourth Edition 7-3
Writing Pseudocode
1. After creating a flowchart, you write the pseudocode. Use the pseudocode example
provided in the book (see Figure 7-3) to explain that pseudocode is used to create a
model that you can later use as a basis for a real program.
Ensuring the Correct Shell Runs the Script
1. Explain that to ensure that the correct shell is used to interpret your script, you have to
include the command that sets the particular shell to use on the first line of the script.
Setting the Default Shell
1. Explain how you can edit the /etc/passwd file to set the default shell.
2. Stress that you should be very careful when editing this file, or alternatively, use a GUI
tool to edit it (see Figure 7-4).
Using Bash Login and Logout Scripts
1. Describe the role of each of the following files: .bash_profile, .bashrc, /etc/.bashrc,
/etc/bashrc, /etc/bash.bashrc, and .bash_logout. Make sure students understand the
page-pf4
2. Use Figure 7-5 to show a sample .bash_profile script file.
Setting Defaults for Using the vi Editor
1. Use an example to show how to edit the .exrc file to set useful defaults for using the vi
editor.
Quick Quiz 1
1. A(n) ____________________ is a logic diagram that uses a set of standard symbols to
visually explain the sequence of events from the start of a process to its end point.
2. After creating a flowchart, the next step in designing a program is to write
____________________.
3. For your own account, the shell that is set up by default is established by the system
administrator in the ____________________ file.
4. The ____________________ file can be used to automatically set up your vi
environment.
Using the test Command
1. Describe the syntax of the test command. Provide some examples that show how useful
this command is.
Performing Relational Integer Tests with the test Command
1. Use Table 7-1 to describe the integer options of the test command.
2. Introduce the term exit status. Explain how to interpret the exit status of the test
page-pf5
A Guide to Unix Using Linux, Fourth Edition 7-5
Performing String Tests with the test Command
1. Use Table 7-2 to describe the string options of the test command.
Testing Files with the test Command
1. Use Table 7-3 to describe the file evaluation options of the test command.
Performing Boolean Tests with the test Command
2. Use Table 7-4 and a few examples to describe the Boolean options of the test command.
Formatting Record Output
1. Use a couple of examples to show how to use the translate utility, tr, to format record
output.
2. Note that when using tr, you can pipe (|) the output of one command as the input to tr,
or you can use the < redirector operator.
page-pf6
A Guide to Unix Using Linux, Fourth Edition 7-6
Deleting Phone Records
Clearing the Screen
Quick Quiz 2
1. The ____________________ command is used to analyze an expression to determine if
it is true.
2. A(n) ____________________ operator is a logical operator that symbolizes AND, OR,
or NOT to evaluate a relationship, such as a comparison of two expressionsand the
result of the evaluation is either true or false.
3. The ____________________ operator of the test command combines two expressions
and tests a logical AND relationship between them.
4. To format record output, you can use the translate utility, ____________________.
Creating an Algorithm to Place the Cursor
2. Explain why, in the example provided, the quotes around $lname are necessary.
Protecting Against Entering Duplicate Data
1. Introduce the term input validation.
page-pf7
A Guide to Unix Using Linux, Fourth Edition 7-7
Using Shell Functions
Defining a Function from the Command Line
1. Use the example provided in the book to show how to define a function from the
command line, and to show how to use the function from the command line (including
how to pass the arguments).
2. Emphasize that even though shell functions can be defined from the command line,
functions are usually stored in script files and loaded into memory when you log in.
Creating Functions inside Shell Scripts
1. Use the .myfuncs file provided in the book to show how to create several functions
inside a shell script file.
Troubleshooting a Shell Script
1. The book provides several tips for troubleshooting a shell script. Explain the tips in
class and enhance the list with other tips drawn from your programming experience:
a. Ensure script has execute permissions.
b. Be certain first line of script specifies shell to use.
c. Use the sh -n, -v, and -x troubleshooting options.
page-pf8
A Guide to Unix Using Linux, Fourth Edition 7-8
f. Check for syntax errors in the use of commands.
g. Look for the use of command options that are not supported in your distribution
of UNIX/Linux.
Quick Quiz 3
1. Because users do not always enter valid data, a program should always check its input
to ensure the user has entered acceptable information. This is known as
____________________.
2. A shell ____________________ is a group of commands that is stored in memory and
assigned a name.
3. The function accesses the arguments using the positional variables (also called
____________________) $1 to $9.
4. The ____________________ positional parameter contains the name of the script or
function.
page-pf9
A Guide to Unix Using Linux, Fourth Edition 7-9
Class Discussion Topics
1. Have your students used flowcharts or pseudocode before? Ask them to share their
2. Students started writing shell scripts when working on the projects in Chapter 6. Ask
Additional Projects
2. Determine how to keep a record of which user scripts have run during a particular
session or over a number of sessions, and catalogue your findings. Tip: the solution
Additional Resources
1. Tips on good shell programming practices. What #! really does:
page-pfa
A Guide to Unix Using Linux, Fourth Edition 7-10
Key Terms
Boolean operator A logical operator that symbolizes AND, OR, or NOT to evaluate
data file.
pseudocode The instructions that are similar to actual programming statements.
Used to create a model that might later become the basis for a program.
shell function A group of commands stored in memory and assigned a name. Shell
Technical Notes for Hands-On Projects
Students should complete these projects by using the command line, such as a terminal
window; using the Bash shell; and using their own accounts. They should use their home
directories unless otherwise directed. Additional project requirements are listed below.

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.