nerdexam
CompTIA

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.

GNU and Unix Commands

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)
  • A
    2% (1)
  • B
    6% (3)
  • C
    2% (1)
  • D
    90% (46)

Why each option

In Bash, variable assignment requires no spaces around the equals sign and no declaration keyword.

Aset TEST="FOO"

The set builtin is used to set shell options or positional parameters, not to assign named variables.

BTEST = "FOO"

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.

Cvar TEST="FOO"

var is not a Bash keyword; it is used for variable declaration in languages like JavaScript and is not recognized in Bash.

DTEST="FOO"Correct

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

#bash variables#variable assignment#shell syntax

Community Discussion

No community discussion yet for this question.

Full LX0-103 Practice