Soru

Zorluk: OrtaBasic Scripting Languages and Constructs

A Linux administrator is troubleshooting an automated system maintenance script saved with a `.sh` file extension. The script needs to verify whether a destination directory stored in an environment variable named `TARGET_PATH` exists before initiating a file copy operation. However, the script generates a syntax error at execution. Which of the following represents the correct syntax to reference this environment variable in a Linux Bash shell script?

  1. $TARGET_PATHCevap
  2. B
    %TARGET_PATH%
  3. C
    $env:TARGET_PATH
  4. D
    var TARGET_PATH

Cevap

The syntax $TARGET_PATH correctly references environment variables within a Linux Bash shell script.
In Linux Bash shell scripts (`.sh`), environment variables are accessed by prefixing the variable identifier with a dollar sign (`),suchas`), such as ` TARGET_PATH` or `${TARGET_PATH}`.

Adım Adım Çözüm

1
Identify the scripting environment based on the file extension.
The .sh extension indicates a Unix/Linux shell script running under an environment such as Bash.
Different scripting runtimes use distinct syntaxes for referencing environment variables.
2
Evaluate the correct variable referencing rule for Bash.
In Bash shell scripting, variables are expanded by prefixing the variable name with a dollar sign (),suchas), such as TARGET_PATH or ${TARGET_PATH}.
Prefixing with $ signals the interpreter to evaluate the value stored in the environment variable.

Anahtar Kavram

Environment Variable Syntax in Shell Scripts
Tahmini Süre:1m 0s
Bu soruyu puanla