Which of the following is a valid variable assignment?

  • Post author:
  • Post category:Blog
  • Post last modified:September 22, 2023
  • Reading time:2 mins read

Which of the following is a valid variable assignment?

  • alpha-init=5
  • MY VAR= “set to one”
  • 2=xyz
  • APP_VAR=’zero’
Explanation & Hint:

The valid variable assignment among the options you provided is:

APP_VAR='zero'

Variable names in many programming languages, including Bash scripting, typically cannot start with a number or contain spaces. They also usually cannot contain special characters other than underscores.

So, the first three options are not valid variable assignments:

  1. alpha-init=5: Variable names cannot have hyphens in them.
  2. MY VAR= "set to one": Variable names cannot contain spaces.
  3. 2=xyz: Variable names cannot start with a number.

The fourth option, APP_VAR='zero', follows the correct format for variable assignment in most programming languages, where you use the equals sign (=) to assign a value to a variable and the value is enclosed in single or double quotes.

For more Questions and Answers:

NDG Introduction to Linux II 2.21 | Chapter 1: Advanced Shell Features Exam Answers