Soru

Zorluk: OrtaBasic Scripting Languages and Constructs

A system administrator is developing a Bash shell script (.sh) to automate daily system backups. While attempting to set a variable for the maximum allowed backup retry attempts, the administrator adds the line `RETRY_COUNT = 5` to the script. When executing the script in a Linux terminal, the shell returns the error message `RETRY_COUNT: command not found`. Which of the following best explains the cause of this error?

  1. Bash interprets spaces around the equals sign as separating a command name from its arguments rather than performing a variable assignment.Cevap
  2. B
    Variables in Bash must include a leading dollar sign during assignment, such as `$RETRY_COUNT = 5`.
  3. C
    Bash requires all user-defined variables to be initialized using the `set` command prior to assignment.
  4. D
    Integer values assigned within shell scripts must be enclosed in double quotation marks to be recognized as valid literal values.

Cevap

Bash interprets spaces around the equals sign as separating a command name from its arguments rather than performing a variable assignment.
In Linux shell scripting (Bash), variable assignment is strictly whitespace-sensitive. The syntax requires `VARIABLE=value` with no spaces surrounding the equals sign. When spaces are introduced (`RETRY_COUNT = 5`), the shell treats `RETRY_COUNT` as the program/command to execute and passes `=` and `5` as parameters. Because no executable named `RETRY_COUNT` exists in the environment path, the terminal returns a `command not found` error.

Adım Adım Çözüm

1
Analyze the reported script line and error output.
The line `RETRY_COUNT = 5` resulted in `RETRY_COUNT: command not found`.
The shell parser evaluates the first word on a line as an executable command name when spaces separate words.
2
Evaluate Bash variable assignment rules.
Bash variable assignment construct syntax is `VARNAME=value` with no whitespace surrounding the `=` operator.
Including whitespace around `=` breaks the token into command (`RETRY_COUNT`), argument 1 (`=`), and argument 2 (`5`).
3
Select the option that correctly identifies the parsing behavior.
The explanation noting that spaces cause the shell to interpret the variable name as an executable command is correct.
This directly explains why a `command not found` error was thrown.

Anahtar Kavram

Bash Scripting Variable Assignment Syntax
Bu soruyu puanla