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?
Correct Answer
B. False
Explanation
Standard Input can also be redirected to/from a file. When a command requires input from the user, it can be redirected from a file using the "
2.
Before a user-defined variable can be used by
processes that run in subshells, that variable must be ____________.
Correct Answer
C. Exported
Explanation
Before a user-defined variable can be used by processes that run in subshells, that variable must be exported. Exporting a variable makes it available to child processes, including subshells, so that they can access and use the variable's value.
3.
The alias command can be used to make a shortcut
to a single command. True or False?
Correct Answer
A. True
Explanation
The alias command is used in computer systems to create shortcuts or alternative names for a command or a set of commands. By using the alias command, users can create a shorter or more convenient name for a command, making it easier to remember and use. Therefore, the statement that the alias command can be used to make a shortcut to a single command is true.
4.
Which of the following files is always executed
immediately after a user logs in to a Linux system and receives a BASH shell?
Correct Answer
A. /etc/profile
Explanation
The file /etc/profile is always executed immediately after a user logs in to a Linux system and receives a BASH shell. This file is a system-wide configuration file that sets environment variables and runs commands that are applicable to all users on the system. It provides a global configuration for the BASH shell and initializes the user's environment.
5.
Which command could you use to see a list of all
environment and user-defined shell variables as well as their current
values?
Correct Answer
C. Set
Explanation
The command "set" can be used to see a list of all environment and user-defined shell variables along with their current values.
6.
Every if
construct begins with if and
must be terminated with?
Correct Answer
D. Fi
Explanation
The correct answer is "fi" because in programming, "fi" is used to terminate an if construct in certain programming languages like Bash. "fi" is the counterpart of "if" and it signifies the end of the conditional statement. Without the "fi" keyword, the if construct would be incomplete and the program may throw an error.
7.
Which of the following will display the message
welcome home if the cd /home/user1 command is successfully
executed?
Correct Answer
A. Cd /home/user1 && echo “welcome home”
Explanation
The correct answer is "cd /home/user1 && echo “welcome home”". This is because the "&&" operator in the command ensures that the second command (echo "welcome home") is only executed if the first command (cd /home/user1) is successful. So if the cd /home/user1 command is successfully executed, it will display the message "welcome home".
8.
The current value for the HOME variable is
displayed by which of the following commands? (Choose all that apply.)
Correct Answer(s)
B. Echo ~
C. Echo $HOME
Explanation
The correct answers are "echo ~" and "echo $HOME".
The command "echo ~" will display the current value of the HOME variable by expanding the tilde (~) character, which represents the home directory.
The command "echo $HOME" will directly display the value of the HOME variable, as the variable is preceded by a dollar sign ($).
9.
Which of the following file descriptor numbers
represents stdout?
Correct Answer
C. 1
Explanation
The correct answer is 1 because in Unix-like operating systems, file descriptor number 1 represents stdout, which is the standard output.
10.
Which of the following operators reverses the
meaning of a test statement?
Correct Answer
D. !
Explanation
The operator "!" is used to reverse the meaning of a test statement. It is a logical operator called the "not" operator, which negates the value of a boolean expression. For example, if a test statement is true, using "!" before it will make it false, and vice versa.
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?
Correct Answer
C. When you use the cat command at the command prompt with the intention of viewing a text file, the date appears instead.
Explanation
Using the alias command to create an alias for the date command named cat would cause the date command to be executed instead of the cat command when using the cat command to view a text file. This means that instead of displaying the contents of the text file, the current date and time would be displayed.
12.
How do you indicate a comment line in a shell
script?
Correct Answer
D. Begin the line with #.
Explanation
In a shell script, a comment line is indicated by beginning the line with a # symbol. This symbol tells the shell to ignore everything after it on that line. It is commonly used to add explanatory or descriptive notes within the script, which are not executed as part of the code.
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?
Correct Answer
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.
Explanation
When redirecting the Standard Error to a file called Errors, if you do not append the Standard Error to the Error file, the file gets overwritten when the command is run again. This means that the previous error messages are replaced with the new ones, resulting in only two error messages being present in the file after repeating the procedure.
14.
The sed and awk commands are filter commands commonly used to format data
within a pipe. True or False?
Correct Answer
A. True
Explanation
The sed and awk commands are indeed filter commands commonly used to format data within a pipe. These commands allow users to manipulate and transform text data in various ways, such as searching for patterns and replacing text (sed) or extracting and manipulating columns of data (awk). Therefore, the statement "The sed and awk commands are filter commands commonly used to format data within a pipe" is true.
15.
What is wrong with the following command string ls /etc/hosts >listofhostfile?
Correct Answer
A. Nothing is wrong with the command.
Explanation
The given command string "ls /etc/hosts >listofhostfile" is correct and does not have any issues. It lists the contents of the /etc/hosts file and redirects the output to a file named listofhostfile.
16.
Which of the following is not necessarily
generated by every command on the system? (Choose all that apply.)
Correct Answer(s)
A. Standard Input
B. Standard Deviation
Explanation
Standard Input and Standard Deviation are not necessarily generated by every command on the system. Standard Input is the input stream where a command receives its input, and Standard Deviation is a statistical measure of the amount of variation or dispersion in a set of values. While Standard Output and Standard Error are commonly generated by commands to display output and error messages respectively, the presence of Standard Input and Standard Deviation depends on the specific command and its functionality.
17.
Which construct can be used in a shell script to
read Standard Input and place it in a variable?
Correct Answer
A. Read
Explanation
The "read" construct can be used in a shell script to read Standard Input and place it in a variable. This allows the script to accept user input and store it for further processing or manipulation. By using the "read" command, the script can prompt the user for input and then store that input in a variable for later use in the script.
18.
- A variable identifier must ____________.
Correct Answer
A. Not begin with a number
Explanation
A variable identifier must not begin with a number because in most programming languages, variable names cannot start with a numeric digit. They must start with a letter or an underscore. This is because starting a variable name with a number can cause confusion and may lead to syntax errors.
19.
What does >> accomplish when entered on the
command line after a command?
Correct Answer
D. It appends Standard Ouput to a file.
Explanation
When the ">>" symbol is entered on the command line after a command, it appends the Standard Output of that command to a file. This means that the output of the command will be added to the end of the specified file, rather than overwriting the file or creating a new one. This is useful when you want to continuously add new content to a file without losing the existing content.
20.
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 program and answered Blue when prompted?
Correct Answer
B. The answer is not red nor blue.
Explanation
The correct answer is "The answer is not red nor blue." This is because the user is prompted to enter their favorite color and if their input is "Blue", the condition in the if statement will evaluate to false. Therefore, the script will execute the else block and display "The answer is not red nor blue."