Chapter 7 Questions
Because stderr and stdout represent the results of a command and stdin represents the input required for a command, only stderr and stdout can be redirected to/from a file. True or False? 1. True 2. False
Answer: 2. False
A for construct is a loop construct that processes a specified list of objects. As a result, it is executed as long as there are remaining objects to process. True or False? 1. True 2. False
Answer: 1. True
You attempt to perform the git commit -m "Added listdir function" but the command fails. What are possible reasons for the failure? (Choose all that apply.) 1. The user performing the commit is not running the command from within the Git repo directory. 2. The master branch was not specified within the command itself. 3. No files were added to the Git index beforehand. 4. The user performing the commit has not set their Git user information.
Answer: 1. The user performing the commit is not running the command from within the Git repo directory. 3. No files were added to the Git index beforehand. 4. The user performing the commit has not set their Git user information.
Both aliases and functions can be used to store commands that can be executed, but functions can also accept positional parameters. True or False? 1. True 2. False
Answer: 1. True
The sed and awk commands are filter commands commonly used to format data within a pipe. True or False? 1. True 2. False
Answer: 1. True
Every if construct begins with if and must be terminated with? 1. fi 2. stop 3. end 4. endif
Answer: 1. fi
Which of the following operators reverses the meaning of a test statement? 1. -o 2. ! 3. #! 4. -a
Answer: 2. !
Which of the following variables could access the value "/etc" within the sample shell script, if the sample shell script was executed using the bash sample /var /etc /bin command? 1. $1 2. $2 3. $3 4. $0
Answer: 2. $2
The current value for the HOME variable is displayed by which of the following commands? (Choose all that apply.) 1. echo ls HOME 2. echo $HOME 3. echo ~ 4. echo HOME=
Answer: 2. echo $HOME 3. echo ~
Which construct can be used in a shell script to read stdin and place it in a variable? 1. verify 2. read 3. test 4. sum
Answer: 2. read
Which of the following lines can be used to perform command substitution within a shell script? (Choose all that apply.) 1. ${!command} 2. ${command} 3. $(command) 4. `command`
Answer: 3. $(command) 4. `command`
How do you indicate a comment line in a shell script? 1. Begin the line with !. 2. Begin the line with #!. 3. Begin the line with #. 4. There are no comment lines in a shell script.
Answer: 3. Begin the line with #.
Before a user-defined variable can be used by processes that run in subshells, that variable must be __________. 1. Redirected to the BASH shell 2. Validated by running the env command 3. Exported 4. Imported
Answer: 3. Exported
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? 1. It cannot be done because there already is a command cat on the system. 2. There is no effect until the alias is imported because it is a user-declared variable. 3. When you use the cat command at the command prompt with the intention of viewing a text file, the date appears instead. 4. It cannot be done as there already is an environment variable cat associated with the cat command.
Answer: 3. When you use the cat command at the command prompt with the intention of viewing a text file, the date appears instead.
Which of the following files is always executed immediately after any user logs in to a Linux system and receives a BASH shell? 1. ~/.bash_profile 2. ~/.profile 3. ~/.bash_login 4. /etc/profile
Answer: 4. /etc/profile
What does &> accomplish when entered on the command line after a command? 1. It does not accomplish anything 2. It redieccts stderr and stdin to the same location 3. It appends stdout to a file 4. It redirects both stderr and stdout to the same location
Answer: 4. It redirects both stderr and stdout to the same location
Consider the following shell script: echo -e "What is your favorite color?--> \c" read REPLY if [ "$REPLY" = "red" -o "$REPLY" = "blue" ] then echo "The answer is red or blue." else echo "The answer is not red nor blue." fi What would be displayed if a user executes this shell script and answers Blue when prompted? 1. The answer is red or blue. The answer is not red nor blue 2. The answer is red or blue 3. The code would cause an error 4. The answer is not red nor blue
Answer: 4. The answer is not red nor blue
You have redirected stderr 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? 1. After you open the file and view the contents, the contents are lost. 2. The system generated different stdout. 3. You must specify a new file each time you redirect as the system creates the specified file by default. 4. You did not append the stderr to the Error file, and, as a result, it was overwritten when the command was run a second time.
Answer: 4. You did not append the stderr to the Error file, and, as a result, it was overwritten when the command was run a second time.
Which of the following will display the message welcome home if the cd /home/user1 command is successfully executed? 1. cat "welcome home" || cd /home/user1 2. cd /home/user1 || cat "welcome home" 3. echo "welcome home" && cd /home/user1 4. cd /home/user1 && echo "welcome home"
Answer: 4. cd /home/user1 && echo "welcome home"
Which command could you use to see a list of all environment and user-defined shell variables as well as their current values? 1. ls /var 2. echo 3. env 4. set
Answer: 4. set