Bird
0
0

Which PowerShell expression correctly detects if the script is running on a Unix-based system?

easy📝 Syntax Q3 of 15
PowerShell - Cross-Platform PowerShell
Which PowerShell expression correctly detects if the script is running on a Unix-based system?
A$PSVersionTable.Platform -eq 'Unix'
B$env:OS -eq 'Linux'
C$PSVersionTable.Platform -eq 'Windows'
D$env:OS -eq 'Unix'
Step-by-Step Solution
Solution:
  1. Step 1: Identify platform property

    $PSVersionTable.Platform returns 'Unix' on Linux/macOS.
  2. Step 2: Check correct comparison

    Comparing to 'Unix' is the standard way to detect Unix-based OS.
  3. Final Answer:

    $PSVersionTable.Platform -eq 'Unix' -> Option A
  4. Quick Check:

    Use $PSVersionTable.Platform for OS detection [OK]
Quick Trick: Check $PSVersionTable.Platform equals 'Unix' [OK]
Common Mistakes:
  • Using environment variables that differ per OS
  • Checking for 'Linux' string directly
  • Assuming $env:OS exists on all platforms

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes