FIND YOUR NEXT FEW LINES

Results for “working”

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

162 snippets foundClear filters
Bash ScriptsParameter expansion

Distinguish unset variables from empty strings

Bash Scripts: Omitting the colon tests only whether a variable is unset; including it also treats an empty value as missing.

Bash Scripts✓ Tested
Bash ScriptsProcesses & environment

Export a value to child processes

Bash Scripts: Only exported shell variables are inherited through the environment.

Bash Scripts✓ Tested
Bash ScriptsParameter expansion

Extract a basename without an external process

Bash Scripts: Double hash removes the longest matching prefix ending in a slash.

Bash Scripts✓ Tested
Bash ScriptsParameter expansion

Extract a parent path with parameter expansion

Bash Scripts: Percent removes the shortest matching slash-and-suffix portion.

Bash Scripts✓ Tested
Bash ScriptsParameter expansion

Extract a substring by offset and length

Bash Scripts: Bash substring offsets start at zero for an ordinary string.

Bash Scripts✓ Tested
Bash ScriptsText parsing & arithmetic

Format a numeric label with leading zeroes

Bash Scripts: Use a constant printf format string and supply values as separate arguments.

Bash Scripts✓ Tested
Bash ScriptsArguments & decisions

Forward all arguments without changing their boundaries

Bash Scripts: Quoted at-sign preserves empty arguments and embedded spaces.

Bash Scripts✓ Tested
Bash ScriptsFunctions & arguments

Give a function an optional argument

Let callers omit a value while keeping nounset enabled.

optional argument✓ Tested
Bash ScriptsFunction scope & composition

Give a function its own positional parameters

Bash Scripts: A function receives its call arguments without replacing the caller’s positional parameters.

Bash Scripts✓ Tested
Bash ScriptsFiles & reliability

Handle a filename pattern with no matches

Use nullglob so an unmatched pattern produces an empty array.

nullglob✓ Tested
Bash ScriptsProcesses & environment

Handle a nonzero background-job exit

Bash Scripts: Wait reports a child’s exit code; put it in a conditional when failure is expected.

Bash Scripts✓ Tested
Bash ScriptsFunctions & arguments

Handle an expected command failure

Branch on a command’s exit code without aborting the script.

exit status✓ Tested