]> git.corax.cc Git - toolbox/commitdiff
include/array: Add functions for printing and sorting arrays
authorMatthias Kruk <m@m10k.eu>
Sun, 28 Mar 2021 01:38:52 +0000 (10:38 +0900)
committerMatthias Kruk <m@m10k.eu>
Sun, 28 Mar 2021 01:38:52 +0000 (10:38 +0900)
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

index 2ff4b28542733394cf8baafaf88fdd0dae8eecaf..ced54d3216922bb5cb0ba3349c835efa549a74ee 100644 (file)
@@ -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
+}