Bird
0
0

You want to write a script that works on Windows and Linux to list files. Which approach is best?

hard📝 Application Q15 of 15
PowerShell - Basics and Environment
You want to write a script that works on Windows and Linux to list files. Which approach is best?
AWrite a PowerShell script using Get-ChildItem and run PowerShell Core on both OS
BWrite a Bash script using ls and run it only on Linux
CWrite a CMD batch file using dir and run it on Windows only
DWrite separate scripts for each OS and manually switch
Step-by-Step Solution
Solution:
  1. Step 1: Consider cross-platform support

    PowerShell Core (PowerShell 7+) runs on Windows and Linux, supporting Get-ChildItem on both.
  2. Step 2: Evaluate other options

    Bash scripts work only on Linux/macOS; CMD batch files only on Windows; separate scripts add complexity.
  3. Final Answer:

    Write a PowerShell script using Get-ChildItem and run PowerShell Core on both OS -> Option A
  4. Quick Check:

    Cross-platform scripting = PowerShell Core + Get-ChildItem [OK]
Quick Trick: PowerShell Core runs cross-platform, unlike CMD or Bash alone [OK]
Common Mistakes:
  • Assuming Bash works on Windows by default
  • Thinking CMD scripts run on Linux
  • Ignoring cross-platform PowerShell Core availability

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes