Results for “Inspecting the working tree”
Small, practical examples. Search by task or narrow things down below.
Limit a beginner function variable to local scope
Bash Scripts: Limit a beginner function variable to local scope with a small standalone Bash program.
Bash Scripts✓ Tested
List files changed by the current commit
Git: diff-tree exposes the paths changed between a commit and its parent.
Git✓ Tested
Load functions from a trusted local script
Bash Scripts: Source executes a file in the current shell so its function definitions remain available.
Bash Scripts✓ Tested
Look up values in an associative array
Use named keys for a small in-memory configuration table.
dictionary✓ Tested
Loop over an array safely
Preserve spaces in array elements while iterating.
array✓ Tested
Observe command substitution’s trailing-newline removal
Bash Scripts: Command substitution removes trailing newlines while preserving embedded ones.
Bash Scripts✓ Tested
Parse a short option with getopts
Read a named option and handle invalid flags explicitly.
getopts✓ Tested
Parse a small set of long options
Bash Scripts: Use a loop and case statement to consume a value-bearing long option.
Bash Scripts✓ Tested
Parse digits with leading zeroes as decimal
Bash Scripts: The 10# prefix avoids Bash treating a leading zero as an octal notation.
Bash Scripts✓ Tested
Pass a variable to standard input
Bash Scripts: A here-string supplies the expanded value followed by a newline.
Bash Scripts✓ Tested
Prepend items while preserving existing array values
Bash Scripts: Construct a new array with the new values before the quoted original expansion.
Bash Scripts✓ Tested
Preserve a failure status while an EXIT trap runs
Bash Scripts: Capture the status immediately on entry to the trap before running cleanup commands.
Bash Scripts✓ Tested