Soru

Zorluk: OrtaBasic Scripting Languages and Constructs

A desktop support technician is writing a Windows Batch script (`.bat`) to automate system profile configuration during user logon. The script must reference the currently logged-in user's account name dynamically from the system environment. Which of the following syntaxes correctly formats an environment variable within a Windows Batch script?

  1. %USERNAME%Cevap
  2. B
    $USERNAME
  3. C
    $env:USERNAME
  4. D
    var USERNAME

Cevap

Enclosing the variable name between percent signs (%USERNAME%) is the correct construct for environment variables in Windows Batch scripts.
In Windows Batch (`.bat`) scripting, environment variables are referenced by surrounding the variable name with percent signs, such as %USERNAME%. When the batch file executes, the Command Prompt interpreter replaces the expression with the actual environment variable value.

Adım Adım Çözüm

1
Identify the target scripting language and objective from the scenario.
The target language is Windows Batch (`.bat`) and the goal is to reference a system environment variable.
Different scripting environments utilize specific syntax rules for variable declaration and retrieval.
2
Evaluate the syntax rule for environment variables in Windows Command Prompt / Batch.
Windows Batch environment variables are delimited using percent signs surrounding the variable name (e.g., %VARIABLE_NAME%).
The command processor recognizes percent signs as delimiters to replace the variable placeholder with its runtime value.

Anahtar Kavram

Windows Batch Environment Variable Syntax
Tahmini Süre:1m 0s
Bu soruyu puanla