Results for “script”
Small, practical examples. Search by task or narrow things down below.
Loop over an array safely
Preserve spaces in array elements while iterating.
array✓ Tested
Name a self-contained embedded document
HTML: Give an iframe a descriptive title and provide its small document with srcdoc.
HTML✓ Tested
Narrow a union using typeof
Handle text and numeric values with separate branches.
union✓ Tested
Parse a short option with getopts
Read a named option and handle invalid flags explicitly.
getopts✓ Tested
Read a file without losing its last line
Handle spaces, backslashes, and a final line without a newline.
read lines✓ Tested
Read a nested optional value
Avoid dereferencing a missing nested object.
optional chaining✓ Tested
Read a property with keyof
Keep the key and returned value tied to an object type.
keyof✓ Tested
Remove a filename extension
Keep the path while removing its final extension.
filename✓ Tested
Remove duplicate values with a Set
Keep the first occurrence order while deduplicating.
Set✓ Tested
Replace a text file with an atomic rename
Prepare new content beside the target before renaming it into place.
atomic write✓ Tested
Replace every occurrence in a string
Substitute text directly with Bash parameter expansion.
replace✓ Tested
Return text from a shell function
Capture a function’s output with command substitution.
function✓ Tested