LX0-103 · Question #45
Which of the following command sets the Bash variable named TEST with the content FOO?
The correct answer is D. TEST="FOO". In Bash, variable assignment requires no spaces around the equals sign and no declaration keyword.
Question
Which of the following command sets the Bash variable named TEST with the content FOO?
Options
- Aset TEST="FOO"
- BTEST = "FOO"
- Cvar TEST="FOO"
- DTEST="FOO"
How the community answered
(51 responses)- A2% (1)
- B6% (3)
- C2% (1)
- D90% (46)
Why each option
In Bash, variable assignment requires no spaces around the equals sign and no declaration keyword.
The set builtin is used to set shell options or positional parameters, not to assign named variables.
Spaces around the = sign cause Bash to interpret TEST as a command and = and "FOO" as its arguments, resulting in a command-not-found error.
var is not a Bash keyword; it is used for variable declaration in languages like JavaScript and is not recognized in Bash.
The correct Bash syntax for variable assignment is NAME=VALUE with no spaces and no keyword. TEST="FOO" directly assigns the string FOO to the variable TEST, following the shell grammar rule that any spaces around = would cause the shell to interpret TEST as a command name rather than a variable.
Concept tested: Bash shell variable assignment syntax
Source: https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameters
Topics
Community Discussion
No community discussion yet for this question.