52 lines
1.8 KiB
Markdown
52 lines
1.8 KiB
Markdown
# Useful BASH snippets.
|
|
|
|
## Useful References
|
|
|
|
https://devhints.io/bash
|
|
https://sharats.me/posts/shell-script-best-practices/ - awesome template of Good Things (TM) ...
|
|
... which then leads to https://news.ycombinator.com/item?id=33354286 - I need to read and consume this properly, so many interesting tool and usage suggestions.
|
|
|
|
## one_liners.bash
|
|
|
|
Collection of simple tricks not big enough to need a separate file.
|
|
|
|
## 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.
|
|
|
|
## tput_colours_etc.bash
|
|
|
|
Using tput command to modify visual output, for example text colours.
|
|
|
|
## usage_help.bash
|
|
|
|
Put your usage output in a function to make it easily callable from multiple places as required.
|