LPI
010-100 · Question #66
010-100 Question #66: Real Exam Question with Answer & Explanation
The correct answer is A. text=olaf\ is\ home E. text="olaf is home". Shell variable assignment requires no $ on the left-hand side, no spaces around =, and spaces within the value must be quoted or escaped.
Question
Which of the following commands will set the variable text to olaf is home? (Select TWO answers)
Options
- Atext=olaf\ is\ home
- Btext=$olaf is home
- C$text='olaf is home'
- Dtext=='olaf is home'
- Etext="olaf is home"
Explanation
Shell variable assignment requires no $ on the left-hand side, no spaces around =, and spaces within the value must be quoted or escaped.
Common mistakes.
- B. $olaf would be expanded as a separate variable (likely empty), and 'is home' would be parsed as a command to execute rather than part of the assignment, causing an error.
- C. Variable names on the left side of an assignment must not be prefixed with $; the $ sigil is only used when reading a variable's value, making this syntax invalid.
- D. The double equals operator == is a comparison operator, not an assignment operator; this would assign the literal string ='olaf is home' (with the leading =) to text, not the intended value.
Concept tested. Shell variable assignment syntax with spaces
Reference. https://www.gnu.org/software/bash/manual/html_node/Shell-Parameters.html
Community Discussion
No community discussion yet for this question.