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
[Both the ~ metacharacter and HOME variable list the current user's home directory.]
What does &> accomplish when entered on the command line after a command?
A. It redirects stderr and stdout to the same location.
[You can use the &> syntax to perform stdout and stderr redirection to a single file.]
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?
C. $2
[The $2 positional parameter refers to the second argument to the shell script. For the sample shell script in this question, "/etc" is the second argument.]
The sed and awk commands are filter commands commonly used to format data within a pipe.
True
[Both sed and awk are commonly used to modify and format the output of data within a pipe.]
Which command could you use to see a list of all environment and user-defined shell variables as well as their current values?
C. set
[The set command displays all variables in the current shell. The env command only displays exported variables in the current shell.]
How do you indicate a comment line in a shell script?
C. Begin the line with #.
[Any lines that start with a # are not executed by the shell and are used to provide comments within a shell script.]
Both aliases and functions can be used to store commands that can be executed, but functions can also accept positional parameters.
True
[Functions can accept arguments (positional parameters) while aliases cannot.]
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?
B. 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.
[When using the > symbol for output redirection, existing files are first cleared by the shell before the command is executed.]
Every if construct begins with if and must be terminated with _____.
C. fi
[You must end an if statement with fi (backwards if) within a shell script.]
Which of the following files is always executed immediately after any user logs in to a Linux system and receives a BASH shell?
C. /etc/profile
[The first file executed by a BASH shell is /etc/profile.]
A user attempts 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 main 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.
[Before creating a Git commit, you must first be within the Git repo directory and have already staged the appropriate files to the Git index and have Git user information set.]
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.
False
[You can redirect stdin from a file.]
Which of the following lines can be used to perform command substitution within a shell script? (Choose all that apply.)
B. `command`
d. $(command)
[You can surround a command with backquotes (`) or use $(command) syntax to perform command substitution.]
Before a user-defined variable can be used by processes that run in subshells, that variable must be _____.
B. exported
[Only exported variables will run within subshells.]
Which of the following will display the message welcome home if the cd /home/user1 command is successfully executed?
B. cd /home/user1 && echo "welcome home"
[The conditional AND operator (&&) executes the right command only if the left command was successful (i.e., returned a true exit status).]
Which construct can be used in a shell script to read stdin and place it in a variable?
A. read
[The read command prompts the user for input and saves that input to a variable supplied as an argument.]
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?
B. When you use the cat command at the command prompt with the intention of viewing a text file, the date appears instead.
[Because aliases are searched for and executed before commands listed within the PATH variable, an alias for cat will always be executed before the cat command on the system.]
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
[A for loop executes a series of commands for a finite list of objects.]
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?
A. The answer is not red nor blue.
[Because Linux commands are case sensitive, and the user entered "Blue" instead of "blue", the else condition is processed in the if statement.]
Which of the following operators reverses the meaning of a test statement?
D. !
[You can use the ! metacharacter to reverse the condition used within a test statement.]