An IT analyst is reviewing a custom Bash shell script (`.sh`) designed to automatically rotate system logs on a Linux workstation when disk usage exceeds a specified percentage. The script contains the following line intended to set a threshold variable:
`THRESHOLD = 80`
When executing the script, the shell returns an error stating `THRESHOLD: command not found`. Which of the following correctly explains the cause of this failure and provides the proper syntax correction?
- Bash does not allow spaces around the assignment operator (`=`); removing the spaces to write `THRESHOLD=80` resolves the error.Cevap
- BBash requires all user-defined variables to be declared using the `set` keyword; changing the line to `set THRESHOLD=80` is required.
- CBash variables storing numeric data must include a dollar sign prefix during assignment; changing the line to `$THRESHOLD=80` is required.
- DBash scripts treat all unquoted numbers as command flags; enclosing the value in quotes as `THRESHOLD = "80"` is required.
Cevap
In Bash shell scripts, variable assignment requires that no spaces precede or follow the equals sign (`=`). The line must be written as `THRESHOLD=80` without spaces.
In Linux Bash shell scripting (`.sh`), variable assignment is strict regarding whitespace. Writing `THRESHOLD = 80` causes the shell parser to look for a command named `THRESHOLD` and pass `=` and `80` to it as parameters. Removing the spaces around the equals sign (`THRESHOLD=80`) informs the parser that a variable is being assigned a value.
Adım Adım Çözüm
Anahtar Kavram
Bash Shell Script Variable Syntax Rules
Tahmini Süre:1m 30s