Soru

Zorluk: OrtaBasic Scripting Languages and Constructs

An IT technician is updating client logon scripts to automatically evaluate system parameters and set environment variables across different operating system environments. Which TWO of the following statements correctly describe variable syntax and environment features for Windows Batch (.bat) and PowerShell (.ps1) scripts? (Select TWO.)

  1. In a Windows Batch script (.bat), environment variables are referenced by enclosing the variable name in percent signs, such as %USERNAME%.Cevap
  2. In a PowerShell script (.ps1), variables are declared and referenced using a leading dollar sign, such as usernameorusername or env:USERNAME.Cevap
  3. C
    In a Windows Batch script (.bat), variables are defined using a leading dollar sign prefix and conditional comparisons require the -eq operator.
  4. D
    In a PowerShell script (.ps1), environment variables are accessed using percent sign wrapping, such as %TEMP%.

Cevap

The correct answers are the statement describing Windows Batch script variable referencing using percent signs (%USERNAME%) and the statement describing PowerShell variable notation using a leading dollar sign (usernameorusername or env:USERNAME).
In Windows Batch (.bat) scripting, environment variables are called by enclosing their names in percent signs (e.g., %USERNAME%). In PowerShell (.ps1) scripting, variables always begin with a dollar sign prefix (e.g., usernameorusername or env:USERNAME for environment variables). Both of these statements accurately represent their respective scripting language standards.

Adım Adım Çözüm

1
Identify the variable syntax rules for legacy Windows Batch (.bat) scripts.
Batch scripts expand environment variables using percent signs, such as %USERNAME% or %TEMP%.
Windows Command Prompt syntax relies on % surrounding variable names for evaluation.
2
Identify the variable syntax rules for Windows PowerShell (.ps1) scripts.
PowerShell prefixes variables with a dollar sign (),using), using env:VARIABLE for environment variables and $variable for script-scoped variables.
PowerShell enforces strong object and variable naming conventions beginning with $.
3
Evaluate and eliminate distractors that mix script syntax rules.
Statements attributing dollar signs and -eq operators to Batch scripts, or percent signs to PowerShell scripts, are incorrect.
Mixing syntax between Batch and PowerShell is a common operational error when editing administration scripts.

Anahtar Kavram

Scripting language syntax differences between Windows Batch (.bat) and PowerShell (.ps1)
Bu soruyu puanla