LFCS practice question 17 of 35
Which of the following commands will set the variable text to olaf is home? (Choose two)
Full set: 260 questionsIn Bash and other POSIX-compliant shells, variable assignment uses the variable=value syntax without spaces around the equals sign. When the value contains spaces, it must be quoted or the spaces must be escaped. Option A uses backslashes (\) to escape the spaces, treating them as literal characters. Option E uses double quotes (") to group the words into a single string argument. Both methods correctly assign the multi-word string "olaf is home" to the variable text.
B. text=$olaf is home: This attempts to assign the value of a variable named $olaf to text and then execute is home as a command, which is incorrect.
C. $text='olaf is home': The dollar sign ($) is used to retrieve a variable's value, not for assignment. This is a syntax error.
D. text=='olaf is home': The double equals (==) is a comparison operator used within conditional expressions, not the assignment operator (=).
GNU Bash Reference Manual. (2022). "3.4 Shell Parameters". In Bash Reference Manual. Free Software Foundation. Retrieved from https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameters
GNU Bash Reference Manual. (2022). "3.1.2.1 Quoting". In Bash Reference Manual. Free Software Foundation. Retrieved from https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Quoting
Sobell, M. G. (2018). A Practical Guide to Linux Commands, Editors, and Shell Programming. Pearson Education. Chapter 4, "The Bourne Again Shell," Section: "Variables: User-Created Variables".
Keep practicing
Take the free LFCS practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other LFCS practice questions
- Question 1Which of the following commands should be added to /etc/bash_profile in order to change t…
- Question 2Which of the following commands reboots the system when using SysV init? (Choose TWO corr…
- Question 3Which of the following tasks can be accomplished using the command date? (Choose TWO corr…
- Question 4Which of the following environment variables overrides or extends the list of directories…
- Question 5Which of the following are syslog facilities? (Choose TWO correct answers.)
- Question 6Which of the following programs uses the hosts.allow file to perform its main task of che…
