LPI
010-160 · Question #87
010-160 Question #87: Real Exam Question with Answer & Explanation
The correct answer is E. USERNAME=bob. Shell variable assignment in bash uses the syntax NAME=value with no spaces around the equals sign and no keyword prefix.
The Power of the Command Line
Question
Which of the following commands sets the variable USERNAME to the value bob?
Options
- Aset USERNAME bob
- B$USERNAME==bob
- Cvar USERNAME=bob
- DUSERNAME==bob
- EUSERNAME=bob
Explanation
Shell variable assignment in bash uses the syntax NAME=value with no spaces around the equals sign and no keyword prefix.
Common mistakes.
- A. The set command is used to set shell options or positional parameters, not to assign named variables - this syntax is invalid for variable assignment.
- B. Prefixing a variable name with $ dereferences it for reading its value; using == is a comparison operator, making this an invalid assignment expression.
- C. The var keyword is used in JavaScript and is not valid shell syntax for variable assignment in bash or POSIX shells.
- D. The == operator performs comparison, not assignment - this expression does not set any variable value.
Concept tested. Bash shell variable assignment syntax
Reference. https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameters
Topics
#shell variables#variable assignment#bash syntax
Community Discussion
No community discussion yet for this question.