1.3 KiB
Useful BASH snippets.
argument_parsing.bash
Handling command line argument / parameter parsing at the beginning of a script.
array_append.bash
How to declare an array, append new elements, iterate over the array for processing.
associative_array.bash
Numerical arrays are referenced using integers, and associative are referenced using strings. Associative Arrays can be handy when you want the key to have meaning.
booleans.bash
BASH doesn't actually have booleans, but there's tricks to make variables behave enough like bools to be useful.
internal_function_w_output_and_return.bash
The right way to have an internal function inside your script, have it output to STDOUT and also have various return values that you can action once the function is completed.
internal_output_tee.bash
The magic way to abuse exec to have your entire script tee to both log file and STDOUT with a simple line at the top, rather than tee pipes plastered throughout your script.
script_runtime.bash
Quick and easy script runtime output.
tmux_launcher.bash
tmux wrapper for another script, e.g. to have top running in part of your terminal while another task runs in the button, then nicely clean up afterwards.
usage_help.bash
Put your usage output in a function to make it easily callable from multiple places as required.