Chapter 7 Lab Quizzes
Which of the following operators reverses the meaning of a test statement? a. #! b. -o c. -a d. !
!
Which of the following characters can be entered at the beginning of a line in a shell script to ensure that line is recognized as a comment rather than try to execute it? a. $ b. > c. % d. #
#
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? a. $0 b. $1 c. $2 d. $3
$2
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?
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?
True
Both aliases and functions can be used to store commands that can be executed, but functions can also accept positional parameters. True or False?
True
The sed and awk commands are filter commands commonly used to format data within a pipe. True or False?
True
Which of the following can be used for comparing values within an if statement? (Choose two.) a. -lt b. -neq c. = d. -grt
a. -lt c. =
Which of the following files can you add filenames to so that the git add * command will not stage them? a. .gitignore b. .gitnopush c. .ignore d. .nopush
a. .gitignore
Which of the following files is always executed immediately after any user logs in to a Linux system and receives a BASH shell? a. /etc/profile b. ~/.bash_profile c. ~/.bash_login d. ~/.profile
a. /etc/profile
What does &> accomplish when entered on the command line after a command? a. It redirects both stderr and stdout to the same location. b. It does not accomplish anything. c. It redirects stderr and stdin to the same location. d. It appends stdout to a file.
a. It redirects both stderr and stdout to the same location.
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.) a. The user performing the commit has not set their Git user information. b. No files were added to the Git index beforehand. c. The user performing the commit is not running the command from within the Git repo directory. d. The master branch was not specified within the command itself.
a. The user performing the commit has not set their Git user information. b. No files were added to the Git index beforehand. c. The user performing the commit is not running the command from within the Git repo directory.
Which of the following lines can be used to perform command substitution within a shell script? (Choose all that apply.) a. `command` b. ${command} c. ${!command} d. $(command)
a. `command` d. $(command)
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
a. cd /home/user1 && echo "welcome home"
Which construct can be used in a shell script to read stdin and place it in a variable? a. read b. sum c. verify d. test
a. read
Consider the following shell script:What would be displayed if a user executes this shell script and answers 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.
b. The answer is not red nor blue.u
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
b. echo ~ c. echo $HOME
Which of the following commands will count the number of lines in a file named data.csv? a. lc data.csv b. wc -l data.csv c. lines data.csv d. count -l data.csv
b. wc -l data.csv
Which of the following will the split command do on a file when no other options are specified? a. It will split a file into new files that are 1 kilobyte each. b. It will split a file into new files that are 1 megabyte each. c. It will split a file into new equally sized files that are 1/10th of the original file size. d. It will split a file into new files that are 1,000 lines each.
c. It will split a file into new equally sized files that are 1/10th of the original file size.
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 because 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 because it is a user-declared variable.
c. When you use the cat command at the command prompt with the intention of viewing a text file, the date appears instead.
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? a. After you open the file and view the contents, the contents are lost. b. The system generated different stdout. c. 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. d. You must specify a new file each time you redirect as the system creates the specified file by default.
c. 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 results would be created by the command sequence: echo 'apple banana carrot dog elephant' | while read a b c; do echo result: $c $b $a; done a. elephant dog carrot b. apple banana carrot dog elephant c. carrot dog elephant banana apple d. carrot dog elephant apple banana
c. carrot dog elephant banana apple
Which of the following will look at the /etc/passwd file for any lines containing the word root and display them out to the screen while simultaneously writing the results to a file? (Choose two.) a. cat /etc/passwd | grep root | merge ~/root.txt b. cat /etc/passwd | grep root >> ~/root.txt c. grep root /etc/passwd | tee ~/root.txt d. grep root /etc/passwd | split ~/root.txt
c. grep root /etc/passwd | tee ~/root.txt
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 #.
d. Begin the line with #.
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
exported
Every if construct begins with if and must be terminated with? _________ a. end b. endif c. stop d. fi
fi
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
set