Bird
0
0

Which of the following is the correct syntax to run a PowerShell script named script.ps1 on macOS terminal?

easy📝 Syntax Q12 of 15
PowerShell - Cross-Platform PowerShell
Which of the following is the correct syntax to run a PowerShell script named script.ps1 on macOS terminal?
A<code>./script.ps1</code>
B<code>run script.ps1</code>
C<code>pwsh script.ps1</code>
D<code>powershell -file script.ps1</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to run scripts in PowerShell on macOS

    On macOS, you run PowerShell scripts by calling pwsh followed by the script name.
  2. Step 2: Check each option

    ./script.ps1 tries to run the script directly, which may fail without execution permission and PowerShell context. powershell -file script.ps1 uses Windows syntax. run script.ps1 is invalid. pwsh script.ps1 correctly runs the script with PowerShell.
  3. Final Answer:

    pwsh script.ps1 -> Option C
  4. Quick Check:

    Run scripts with 'pwsh script.ps1' on macOS [OK]
Quick Trick: Use 'pwsh script.ps1' to run scripts on macOS [OK]
Common Mistakes:
  • Trying to run script directly without 'pwsh'
  • Using Windows PowerShell syntax on macOS
  • Using 'run' command which doesn't exist

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes