Labrador Bash library. Collection of functions and libraries that I deem useful for working with Bash.
See https://kamilcuk.github.io/L_lib/ for documentation of the project.
Kindly feel free to have converstations and ask questions on Github discussion.
Report bugs using Github issue.
The library is one file. Download the latest release from github and put in your PATH:
mkdir -vp ~/.local/bin/
curl -o ~/.local/bin/L_lib.sh https://raw.githubusercontent.com/Kamilcuk/L_lib/refs/heads/v1/bin/L_lib.sh
export PATH=~/.local/bin:$PATH
You can use the library in scripts with:
. L_lib.sh -s
You can test the library ad-hoc:
bash <(curl -sS https://raw.githubusercontent.com/Kamilcuk/L_lib/refs/heads/v1/bin/L_lib.sh) L_argparse -- -v -- arg ---- -v world hello
Below is some list with some of the library features. The library contains much more.
- argument parsing in Bash with short, long optiong, subparsers, subfunctions support and shell completion
L_argparse - logging library with levels and configurable output and filtering
L_log_configureL_infoL_logrunL_run - pretty function stack printing usually on ERR trap
L_print_traceback - execute an action on EXIT, any terminating signal or RETURN trap of any function
L_finally - create temporary directory and cd to it for the duration of a function with auto removal after return
L_with_cdL_with_cd_tmpdir - create unidirectional connected two file descriptors
L_pipe - create and manage multiple coprocesses with separate file descriptors for stdin and stdout
L_proc_popenL_proc_communicateL_proc_kill - temporary enable or disable shell features
set -xfor the duration of a commandL_setxL_unsetxL_extglob - easily sort a Bash arrays containing any characters
L_sort - failure handling utilities
L_assertL_dieL_checkL_panic - variables holding color codes depending on terminal support
L_color_detect$L_RED$L_BLUE - checking Bash features and version
$L_BASH_VERSION$L_HAS_BASH4_0$L_HAS_COMPGEN_V$L_HAS_WAIT_N - waiting on multiple PIDs with a timeout ignoring signals and collecting all exit codes
L_wait - simplify storing exit status of a command into a variable
L_exit_toL_exit_to_10 - help with path operations, with PATH or PYTHONPATH manipulation
L_path_stemL_dir_is_emptyL_path_appendL_path_relative_to - string utilities
L_stripL_strupperL_strstrL_html_escapeL_urlencode - split string without remote execution and understant
$''sequencesL_str_split - templating output
L_percent_formatL_fstring - JSON escape
L_json_escape - Cache commands execution with ttl in memory or file
L_cacheL_cache_decorate - Easy writing function utilities by supporting
-v <var>option or extracting comment before functionL_handle_v_scalarL_func_helpL_func_usage_errorL_decorate - All with support for any Bash versions from 3.2 to latest with portability funtions
L_readarrayL_epochrealtime_usecL_compgen -V
L_*prefix for public symbols._L_*prefix for private symbols, including local variables in functions taking a namereference.- Upper case used for global scope readonly variables.
- Lower case used for functions and user mutable variables
- Snake case for everything.
- The option
-v <var>is used to store the result in a variable instead of printing it.- This follows the convention of
printf -v <var>. - Without the
-voption, the function outputs the elements on lines to stdout. - Associated function with
_vsuffix store the result in a hardcoded scratch variableL_v.
- This follows the convention of
LGPL
