FIND YOUR NEXT FEW LINES

Results for “parameter expansion”

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

58 snippets foundClear filters
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 ScriptsGetting Started

Replace text with parameter expansion

Bash Scripts: Replace text with parameter expansion with a small standalone Bash program.

Bash Scripts✓ Tested
Bash ScriptsParameter expansion

Assign a default to an empty or unset variable

Bash Scripts: The colon-equals expansion both supplies and assigns a fallback value.

Bash Scripts✓ Tested
Bash ScriptsParameter expansion

Convert a variable to uppercase

Bash Scripts: Double caret transforms matching lowercase characters in Bash 4 or later.

Bash Scripts✓ Tested
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 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 substring by offset and length

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

Bash Scripts✓ Tested
Bash ScriptsParameter expansion

Read a string’s character length

Bash Scripts: Bash parameter length counts characters under the current locale.

Bash Scripts✓ Tested
Bash ScriptsParameter expansion

Read a variable whose name is stored in another variable

Bash Scripts: Indirect expansion performs one extra variable-name lookup.

Bash Scripts✓ Tested
Bash ScriptsVariables & text

Remove a filename extension

Keep the path while removing its final extension.

filename✓ Tested
Bash ScriptsParameter expansion

Remove a known prefix with a shell pattern

Bash Scripts: The hash expansion removes the shortest matching prefix without changing the original variable.

Bash Scripts✓ Tested
Bash ScriptsVariables & text

Use a default value for an unset variable

Supply a fallback without changing the original variable.

parameter expansion✓ Tested