FIND YOUR NEXT FEW LINES

Results for “script”

Small, practical examples. Search by task or narrow things down below.

407 snippets foundClear filters
Bash ScriptsLoops & decisions

Loop over an array safely

Preserve spaces in array elements while iterating.

array✓ Tested
HTMLImages & embedded documents

Name a self-contained embedded document

HTML: Give an iframe a descriptive title and provide its small document with srcdoc.

HTML✓ Tested
TypeScriptTypes & functions

Narrow a union using typeof

Handle text and numeric values with separate branches.

union✓ Tested
Bash ScriptsFunctions & arguments

Parse a short option with getopts

Read a named option and handle invalid flags explicitly.

getopts✓ Tested
Bash ScriptsLoops & decisions

Read a file without losing its last line

Handle spaces, backslashes, and a final line without a newline.

read lines✓ Tested
TypeScriptSafe data handling

Read a nested optional value

Avoid dereferencing a missing nested object.

optional chaining✓ Tested
TypeScriptUtilities & async

Read a property with keyof

Keep the key and returned value tied to an object type.

keyof✓ Tested
Bash ScriptsVariables & text

Remove a filename extension

Keep the path while removing its final extension.

filename✓ Tested
TypeScriptCollections & records

Remove duplicate values with a Set

Keep the first occurrence order while deduplicating.

Set✓ Tested
Bash ScriptsFiles & reliability

Replace a text file with an atomic rename

Prepare new content beside the target before renaming it into place.

atomic write✓ Tested
Bash ScriptsVariables & text

Replace every occurrence in a string

Substitute text directly with Bash parameter expansion.

replace✓ Tested
Bash ScriptsFunctions & arguments

Return text from a shell function

Capture a function’s output with command substitution.

function✓ Tested