POSIX Shell List ================ [![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/Ventto/posix-shell-list/blob/master/LICENSE) *"This is a POSIX Shell list implementation."* ## Perks * [x] **No requirement**: POSIX-compliant * [x] **Lightweight**: ~100 lines * [x] **Extra**: Additional functions to fit your needs * [x] **Useful**: No internal independency * [x] **Both**: Safe and unsafe (passing argument by reference) versions # Installation * Download it: ```bash $ wget https://raw.githubusercontent.com/Ventto/posix-shell-list/master/liblist.sh ``` * Source the library for including the functions into your Shell script: ```bash . liblist.sh (or) . liblist_unsafe.sh ``` * Each function is independent. So you can copy some functions into your script without sourcing # Functions The whole function documentation is in the following library scripts: * `liblist.sh`: the variable assignation is required for conserving changes * `liblist_unsafe.sh`: uses `eval` special shell builtin for passing argument by reference and set the list variable The following list enumerates all available functions: ``` SAFE | UNSAFE ____________________________________|_______________________________ list ... | list ... list_back | list_back list_contains | list_contains list_count | list_count list_empty | list_empty list_erase | list_erase list_erase_from | list_erase_from list_erase_range | list_erase_range list_eraseat | list_eraseat list_extract | list_extract list_front | list_front list_get | list_get list_indexof | list_indexof list_insert | list_insert list_maps | list_maps list_pop_back | list_pop_back list_pop_front | list_pop_front list_push_back | list_push_back list_push_front | list_push_front list_remove | list_remove list_replace | list_replace list_reverse | list_reverse list_set | list_set list_size | list_size list_sort | list_sort list_sort_reverse | list_sort_reverse ``` # Example Scripts in `test/` offer an exhaustive usage of both libraries. * Quick start (safe version): ```bash lst="$(list 'A' 'B' 'C')" lst="$(list_sort "$lst")" # { C, B, A } if list_empty "$lst"; then echo 'The list is empty.' fi index="$(list_indexof 'D' "$lst")" # '', empty string if [ "$?" -ne 0 ]; then echo 'Element not found.' fi ``` * Quick start (unsafe version): ```bash lst="$(list 'A' 'B' 'C')" list_sort lst # { C, B, A } if list_empty lst; then echo 'The list is empty.' fi index="$(list_indexof lst 'D')" # '', empty string if [ "$?" -ne 0 ]; then echo 'Element not found.' fi ```