A systems administrator is writing a Bash shell script (.sh) on a Linux workstation to parse log files located in a specific directory. The script must define a variable holding the target path /var/log/audit and reference that variable within a loop construct. Which TWO of the following scripting statements and syntax rules must the administrator follow for this Bash script to execute successfully? (Select TWO.)
- Define the variable using the syntax LOG_DIR="/var/log/audit" with no whitespace surrounding the assignment operator.Answer
- Reference the stored variable value using {LOG_DIR} syntax when building script constructs.Answer
- CDefine the variable using the syntax set LOG_DIR = "/var/log/audit" to register it within the current session environment.
- DIterate through files using the construct for %f in ($LOG_DIR/*) do to evaluate each item in the directory.
Answer
Defining the variable without spaces around the equals sign (LOG_DIR="/var/log/audit") and referencing its value using a dollar sign prefix ({LOG_DIR}).
In Bash shell scripting, variables are declared without whitespace surrounding the assignment operator (e.g., LOG_DIR="/var/log/audit"). To expand and evaluate the variable's value in loops or commands, the variable name must be prefixed with a dollar sign ({LOG_DIR}).
Step-by-Step Solution
Key Concept
Bash Environment Variable Assignment and Expansion Syntax
Estimated Time:1m 30s