Networking Chapter 7 Homework Review The Command Using The Man Pages For Sort Both project 718for

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

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
Guide to UNIX Using Linux Fourth Edition
Chapter 7 Solutions
Answers to the Chapter 7 Review Questions
1. You have been asked to write a script for use by the faculty at the engineering school at your
college. The script you write uses the Bash shell, but some faculty members often use a different
shell in their work. How can you best ensure that the Bash shell is invoked when this script is run?
2. Which of the following script statements accomplishes the same thing as the statement: while [
$part” != “alternator” ] ; do ? (Choose all that apply.)
3. Your shell script, called .filetests, contains several functions used to run tests on files, such as to
determine if a file is empty or has the correct permissions. Which of the following is/are true about
.filetests? (Choose all that apply.)
4. When you enter echo $CLR your screen clears very quickly. Which of the following commands
must you have entered previously to enable use of echo $CLR to clear the screen?
5. Your company has assigned you to revise 22 scripts. Since you use the vi editor, how can you set
it to automatically display lines as numbered so it is easier for you to work on these revisions?
6. You use the same five shell functions every day and are looking for a way to ensure they are
available as soon as you log into your account. What can you do??
7. When you enter test -d tmp ; echo $?, you see a 0 displayed on the screen. What does this mean?
8. What does a down arrow represent in a flowchart?
9. Which of the following are examples of Boolean operators used with the test command? (Choose
all that apply.)
10. You have a specialized data file, called customers in which the fields in the file are separated by
the character ^. You want to view this file with a colon between the fields before you convert it to
remove the ^ characters and insert colons. Which of the following commands enables you to view
the file in this way?
11. Which of the following statements enables you to determine if the variable, called value, is less
than 750?
page-pf2
2
12. Some Linux systems use the ______________ script to perform the same actions each time a user
logs out of her account.
13. You have recently met with your company’s budget committee about creating a script to for
producing the same budget reports at the end of each month. Because this is an important
undertaking you’ve started by creating a flowchart. What step should you take next?
14. Which of the following are examples of symbols you might use in a flowchart? (Choose all that
apply.)
15. The script you are creating takes data input to use for updating a file. Before taking the data input,
you want the script to verify that the file to be updated, called clients, exists and that the script user
has permission to write to that file. Which of the following statements enables you to do this?
16. When working on the script in Question 15, which of the following should you consider?
18. In which of the following files would a system administrator set the default shell used by your
account?
19. Which of the following characters are placed right after a function name when you create a shell
function?
20. When you create a shell function from the command line, what character do you enter at the first >
prompt just after you declare the function’s name?
21. What symbol is typically used at the start and end of a flowchart?
22. What is an exit status and with what command is it used?
23. In your organization everyone uses the Bash shell in Red Hat Enterprise Linux and all users use
the same aliases and shell functions. In what file or files can the system administrator place these
aliases and functions so they are available to all users?
24. Create a statement that enables you to determine if the file /source/results is newer than the file
/data/results.
page-pf3
3
25. Create a simple function that determines if the string variable, text, contains no characters (is of
zero length).
Hands-On Projects Tips and Solutions for Chapter 7
Project 7-1
In this project, students view the contents of the files that affect the Bash shell environment:
.bash_profile, .bashrc, .bash_logout, /etc/bashrc, and /etc/profile. (If students are using SUSE or
Knoppix the files they view will be the ones appropriate for those systems.)
Consider discussing with your students the ways in which you recommend altering these files for
different types of users.
Project 7-2
This project shows students how to use the test command to evaluate integer expressions directly from
the command line.
Project 7-3
page-pf4
4
In this project, students begin preparing their environment to continue working on the telephone
number and employee application they started in Chapter 6. Students use the test command to verify
the existence of the source directory. Also, they change the .bash_profile login script to include the
source directory in the PATH environment variable.
Project 7-7
Students employ the test command in this project by modifying the if statement in the veg_choice
script they created and modified in Chapter 6.
Project 7-8
In this project, students modify the while loop in the colors script to employ the test command.
Project 7-9
Project 7-11
This project has students revise the phmenu script to include an option to delete a record. In the code
that students write, they display a query to ensure that a record is to be deleted and use the test
command to determine the yes or no answer to the query. Also, students create a temporary file in the
deletion process and they use the trap command to make certain the temporary file is deleted after it is
no longer needed.
Project 7-12
In this project, students learn a way to clear the screen more quickly by making a script variable for
this purpose. They modify the .bashrc file to add the script variable and export it each time they log in.
Project 7-13
Project 7-15
This project is enables students to create their first simple function that displays the current date.
page-pf5
5
Project 7-16
For this project, students enhance the datenow function they created in Project 7-15 so that it takes an
argument.
In conjunction with this project, consider reviewing in class the ways in which you can use positional
variables ($1, $2, etc.).
Project 7-17
In this project, students create a hidden shell script called .myfuncs that has sorting functions for the
corp_phones file. They will use this script in Hands-on Project 7-19 to put the finishing touches on
their employee telephone number application.
Before students attempt this project, suggest that they review how to use the sort command, either by
going back to Chapter 4 to review the command, by using the man pages for sort, or both.
Project 7-18
For this project, students first execute the .myfuncs script from the command line to make its functions
resident in memory. Next, they edit the .bashrc file so that .myfuncs is loaded during log in.
Discovery Exercises
1. What are the exit statuses of the test command discussed in this chapter and what do they mean?
How can you view the exit status results of the test command directly from the command line?
2. Create a variable called mem_size and set its contents to 1024. Next, use the test command to
determine if the contents of mem_size is less than or equal to 512.
3. Set your shell from the command line to be the Bash shell. Then, use the echo command to verify
the contents of the shell variable. What is now contained in the shell variable?
4. After performing Exercise 3, use the test command to evaluate whether the shell variable contains
a reference to the bash shell and use the echo command to determine the result. (Note that this
provides one way to verify from within a script that the script user is set up to use the Bash shell.).
page-pf6
5. Make certain that your home directory is your current working directory. Use the command to
verify that your source directory exists. How might knowledge of this command be useful when
you create scripts for yourself or others?
6. Switch to your source directory and make a copy of the corp_phones file (which will give you a
valuable backup of the corp_phones file) with the name corp_phones_bak. Using the tr command
as a filter for output from another command, display to the screen the contents of
corp_phones_bak so that all capitalized letters from A to M are lowercase.
7. Make your home directory your current working directory. Use the vi or Emacs editor to
open the veg_choice script you created in Chapter 6. Enter a line in that script to ensure
the script uses the Bash shell. Run veg_choice to ensure your change works properly.
page-pf7
8. Edit the veg_choice script again, but this time change the line: if [ “$veg_name” = “carrots” ] to
use the test command.
9. Create pseudocode and a flowchart for a proposed script that does the following:
Reads and sets the variable M
Reads and sets the variable R
Reads and sets the variable T
Sums M, R, and T in the variable A
Evaluates A to determine if it is greater than 2000.
If A is greater than 2000, prints on the screen “A is over 2000.
If A is less than or equal to 2000 prints on the screen “A is 2000 or less.”
page-pf8
page-pf9
10. Create the script for Exercise 9 and name it evaluate_yourinitials, such as evaluate_jp.. Test your
script.
fi
11. Create a shell variable that outputs the calendar for the current month.
12. How could you set up CALNOW so that it works every time you log in using the Bash shell?
page-pfa
13. List the records in the corp_phones_bak file that you created earlier, so that they are displayed
without colons separating the fields, but have one space between fields instead.
14. Use the vi or Emacs editor to open the nameaddr script you created in Chapter 6. The script should
look similar to the following:
looptest=y
while [ "$looptest" = y ]
do
echo n "Enter Name : "; read name
echo n "Enter Street : "; read street
echo n "Enter City : "; read city
echo n "Enter State : "; read state
echo n "Enter Zip Code: "; read zip
echo n "Continue? (y)es or (n)o: "; read looptest
done
How can you change this script to employ the test command?
15. In your source directory, write a script called “them” in which you create a function called
whoisthere that displays a listing of who is logged in and displays the column headings for the
information displayed.
16. Make the contents of your “them” script resident in memory and test your whoisthere function.
17. Modify your whoisthere function so that you can enter “These are the folks logged in:” as an
argument to appear before you list who is logged into the system.
page-pfb
11
18. What actions do you take next to use the whoisthere function with your modifications?
19. How can you set up your new whoisthere function so that it can be run each time you log in using
the Bash script?
20. Use a one line command to strip out the telephone prefix (219-) and the colons in the
corp_phones_bak file and save the result in a file called noprefix?
21. Troubleshoot the problems with the following script:
#===============================================
Script Name: record_entry
By: TRJackson
#===============================================
looptrack=y
while [ “$looptrack” = 1 ]
do
echo -n “Type in the account number:” read account
echo -n “Type the first and last name:” ; read full_name
echo -n “Type the age:” red age
echo -n “Enter another record?” ; read looptrack
finish
Answer: The following corrections should be made to the script:

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.