Results for “script”
Small, practical examples. Search by task or narrow things down below.
Describe an object with an interface
Require named fields on a reusable object shape.
interface✓ Tested
Detect an error inside a pipeline
Use pipefail to observe failure before the last pipeline command.
pipefail✓ Tested
Discard incidental output from a setup command
PowerShell: Out-Null prevents setup objects from becoming part of a function or script’s useful result.
PowerShell✓ Tested
Dispatch a command with case
Choose an action from a small set of supported commands.
case✓ Tested
Draw a basic rectangle on a labeled canvas
HTML: Canvas requires script to draw pixels; provide alternative content and an accessible label.
HTML✓ Tested
Filter and transform an array
Keep active objects and extract their names.
filter✓ Tested
Give a function an optional argument
Let callers omit a value while keeping nounset enabled.
optional argument✓ Tested
Give an optional property a default
Handle missing object fields with nullish coalescing.
optional✓ Tested
Handle a filename pattern with no matches
Use nullglob so an unmatched pattern produces an empty array.
nullglob✓ Tested
Handle a result with a discriminated union
Separate success data from an error message.
discriminated union✓ Tested
Handle an expected command failure
Branch on a command’s exit code without aborting the script.
exit status✓ Tested
Look up values in an associative array
Use named keys for a small in-memory configuration table.
dictionary✓ Tested