Results for “Arguments & decisions”
Small, practical examples. Search by task or narrow things down below.
Give a function an optional argument
Let callers omit a value while keeping nounset enabled.
optional argument✓ Tested
Handle an expected command failure
Branch on a command’s exit code without aborting the script.
exit status✓ 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
Override the image entrypoint in Compose
Docker / Compose: entrypoint and command combine as executable and arguments.
Docker / Compose✓ Tested
Pass an argument into a worker thread
C++: Thread arguments are copied by default; std::ref explicitly passes a reference.
C++✓ Tested
Read a file without losing its last line
Handle spaces, backslashes, and a final line without a newline.
read lines✓ Tested
Read an image’s default command
Docker / Compose: Config.Cmd contains the command arguments stored in the image.
Docker / Compose✓ Tested
Return text from a shell function
Capture a function’s output with command substitution.
function✓ Tested
Sum a range of integers
Use an arithmetic loop without launching external processes.
arithmetic✓ Tested
Type a function’s inputs and output
Catch mismatched arguments during compilation.
function✓ Tested