From a7f1d5bf5fd1d8264788243dfe6b31a30ba74d63 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Sun, 28 Mar 2021 10:38:52 +0900 Subject: [PATCH] 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. --- include/array.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 +} -- 2.47.3