Script Reference PT0-003
Identify the language first
| Clue | Language |
$var, -eq/-ne, Verb-Noun cmdlets, | objects, Write-Host | PowerShell |
#!/bin/bash, $1, fi/done, [ ... ], backticks/$( ) | Bash |
colons + indentation, def, import, print(), range() | Python |
PowerShell uses $ like Bash, but Bash never uses -eq style operators outside [ ] and never uses Verb-Noun cmdlets.
Python — common exam traps
- Missing
: after if / for / while / def / else / elif / try → SyntaxError
print "x" (no parens) → runs in Py2, SyntaxError in Py3
- Inconsistent indentation → IndentationError
= (assign) vs == (compare) inside a condition
- Using a name before
import (e.g. os.system with no import os) → NameError
range(1,10) stops at 9 — off-by-one
Bash — common exam traps
if needs then … fi; for/while need do … done
[ "$x" = "y" ] — spaces required inside brackets; missing space → error
- Assignment has no spaces:
x=1, not x = 1
- Read a variable with
$x; assign without $
- Unquoted
$var word-splits on spaces/globs
= vs -eq: strings use =, integers use -eq in [ ]
PowerShell — common exam traps
- Comparisons are
-eq -ne -lt -gt -le -ge, never == != < >
- Variables need
$: $path, not path
- Script blocks/loops need matching
{ }
- Pipe passes objects;
Where-Object/ForEach-Object use $_
-match = regex, -like = wildcard (*), -contains = collection membership
Read-then-scan method
- Name the language from one or two tokens.
- Check block openers/closers: colons (Py),
then/fi/do/done (Bash), { } (PS).
- Check comparison vs assignment operators for that language.
- Check every variable is referenced the way that language requires.
- Only then judge logic (off-by-one, wrong flag, wrong cmdlet).
A snippet can be syntactically valid but still wrong for the task. "Clean or Broken?" mode mixes both — read the stated goal, not just the syntax.
Watch out for…
Not every snippet is broken. Some are valid and the trap is a distractor that only *looks* wrong (e.g. a legal $( ) you mistake for an error). Confirm the flaw actually breaks execution or the stated goal before choosing it.