Question

Difficulty: HardBasic Scripting Languages and Constructs

A systems administrator is reviewing multiple maintenance scripts used across Windows and Linux workstations to audit system environment variable access and execution commands. Match each scripting code snippet or construct to its corresponding scripting language environment.

  • $env:COMPUTERNAMEWindows PowerShell (.ps1)
  • echo $HOSTNAMELinux Bash (.sh)
  • WScript.Echo WScript.Arguments(0)VBScript (.vbs)
  • import os; print(os.environ['COMPUTERNAME'])Python (.py)

Answer

The construct 'env:COMPUTERNAMEmatchesWindowsPowerShell(.ps1);echoenv:COMPUTERNAME' matches Windows PowerShell (.ps1); 'echo HOSTNAME' matches Linux Bash (.sh); 'WScript.Echo WScript.Arguments(0)' matches VBScript (.vbs); and 'import os; print(os.environ["COMPUTERNAME"])' matches Python (.py).
Each script construct relies on unique syntactical elements characteristic of its underlying engine: PowerShell uses env:forenvironmentvariables,Bashusesstandardenv: for environment variables, Bash uses standard prefixes with shell built-in commands like echo, VBScript invokes WScript objects, and Python uses module imports (import os) paired with object/dictionary methods.

Step-by-Step Solution

1
Identify the environment variable drive syntax ($env:).
Recognize that $env: indicates a PowerShell environment drive reference.
PowerShell exposes environment variables through the Env: drive namespace.
2
Analyze standard shell variables and echo commands.
Link 'echo $HOSTNAME' to Unix/Linux Bash.
Bash scripts prepend variable names with '$' and utilize built-in shell commands like 'echo'.
3
Identify Windows Script Host object references.
Link 'WScript.Echo' and 'WScript.Arguments' to VBScript.
VBScript executes under WSH/CScript/WSCRIPT engines and accesses host objects via WScript.
4
Examine module import statements and dictionary access syntax.
Link 'import os; print(os.environ[...])' to Python.
Cross-platform scripting in Python relies on importing operating system modules such as 'os'.

Key Concept

Basic Scripting Languages and Constructs
Rate this question