From: Matthias Kruk Date: Sun, 28 Mar 2021 01:38:52 +0000 (+0900) Subject: include/array: Add functions for printing and sorting arrays X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=a7f1d5bf5fd1d8264788243dfe6b31a30ba74d63;p=toolbox include/array: Add functions for printing and sorting arrays Printing and sorting arrays in-line tends to be rather awkward. This commit adds the array_to_lines() and array_sort() functions that take over this task. --- diff --git a/include/array.sh b/include/array.sh index 2ff4b28..ced54d3 100644 --- a/include/array.sh +++ b/include/array.sh @@ -21,3 +21,15 @@ array_contains() { return 1 } + +array_to_lines() { + local item + + for item in "$@"; do + echo "$item" + done +} + +array_sort() { + array_to_lines "$@" | sort -V +}