Guide to Linux+ (2nd Edition) ISBN 0-619-21621-2 End of Chapter 8 Solutions

Download Solution: Click to Download Solution
Solution File Name: Ch08.doc
Unzip Password:

Chapter 8 Solutions
Review Questions

1. Because Standard Error and Standard Ouput represent the results of a command and Standard Input represents the input required for a command, only Standard Error and Standard Ouput can be redirected to/from a file. True or False?

2. Before a user-defined variable can be used by processes that run in subshells, that variable must be __________.
a. imported
b. validated by running the env command
c. exported
d. redirected to the BASH shell

3. The alias command can be used to make a shortcut to a single command. True or False?

4. Which of the following files is always executed immediately after a user logs in to a Linux system and receives a BASH shell?
a. /etc/profile
b. ~/.bash_profile
c. ~/.bash_login
d. ~/.profile

5. Which command could you use to see a list of all environment and user-defined shell variables as well as their current values?
a. ls /var
b. env
c. set
d. echo

6. Every if construct begins with if and must be terminated with?
a. end
b. endif
c. stop
d. fi

7. Which of the following will display the message welcome home if the cd /home/user1 command is successfully executed?
a. cd /home/user1 && echo “welcome home”
b. cat “welcome home” || cd /home/user1
c. cd /home/user1 || cat “welcome home”
d. echo “welcome home” && cd /home/user1

8. The current value for the HOME variable is displayed by which of the following commands? (Choose all that apply.)
a. echo HOME=
b. echo ~
c. echo $HOME
d. echo ls HOME

9. Which of the following file descriptor numbers represents stdout?
a. 2
b. 0
c. 1
d. 3

10. Which of the following operators reverses the meaning of a test statement?
a. #!
b. -o
c. -a
d. !

11. What would be the effect of using the alias command to make an alias for the date command named cat in honor of your favorite pet?
a. It cannot be done as there already is an environment variable cat associated with the cat command.
b. It cannot be done as there already is a command cat on the system.
c. When you use the cat command at the command prompt with the intention of viewing a text file, the date appears instead.
d. There is no effect until the alias is imported as it is a user-declared variable.

12. How do you indicate a comment line in a shell script?
a. There are no comment lines in a shell script.
b. Begin the line with #!.
c. Begin the line with !.
d. Begin the line with #.

13. You have redirected Standard Error to a file called Errors. You view the contents of this file afterward and notice that there are six error messages. After repeating the procedure, you notice that there are only two error messages in this file. Why?
a. After you open the file and view the contents, the contents are lost.
b. The system generated different Standard Ouput.
c. You did not append the Standard Error to the Error file and as a result, it was overwritten when the command was run a second time.
d. You must specify a new file each and every time you redirect as the system creates the specified file by default.

14. The sed and awk commands are filter commands commonly used to format data within a pipe. True or False?

15. What is wrong with the following command string ls /etc/hosts >listofhostfile?
a. Nothing is wrong with the command.
b. The file descriptor was not declared; unless 1 for Standard Ouput or 2 for Standard Error is indicated, the command will fail.
c. The ls command is one of the commands that cannot be used with redirection; you must use | to pipe instead.
d. The file listofhostfile will always only contain Standard Error as a file descriptor was not declared.

16. Which of the following is not necessarily generated by every command on the system? (Choose all that apply.)
a. Standard Input
b. Standard Deviation
c. Standard Ouput
d. Standard Error

17. Which construct can be used in a shell script to read Standard Input and place it in a variable?
a. read
b. sum
c. verify
d. test

18. A variable identifier must _________.
a. not begin with a number
b. not begin with a capital letter
c. start with a number
d. start with an underscore “_”

19. What does >> accomplish when entered on the command line after a command?
a. It redirects both Standard Error and Standard Ouput to the same location.
b. It does not accomplish anything.
c. It redirects Standard Error and Standard Input to the same location.
d. It appends Standard Ouput to a file.

20. Consider the following shell script:
echo -e “What is your favorite color?–> \c”
read REPLY
if [ “$REPLY” = “red” –o “$REPLY” = “blue” ]
echo “The answer is red or blue.”
echo “The answer is not red nor blue.”

What would be displayed if a user executes this program and answered Blue when prompted?
a) The answer is red or blue.
b) The answer is not red nor blue.
c) The code would cause an error.
d) The answer is red or blue. The answer is not red nor blue.

Hands-on Projects

Project 8-1
Project 8-2
Project 8-3
Project 8-4
Project 8-5

Discovery Exercises
Discovery Exercise 1
Discovery Exercise 2
Discovery Exercise 3
Discovery Exercise 4
Discovery Exercise 5
Discovery Exercise 6
Discovery Exercise 7

Add Comment