-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrays.sh
45 lines (34 loc) · 940 Bytes
/
arrays.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env bash
# copy_associative_array() {
# local source=$1
# local target=$2
# eval $(typeset -A -p $source | sed 's/$source=/$target=/')
# }
# copy_array() {
# local source=$1
# local target=$2
# target=("${source[@]}")
# }
clone_associative_array() {
local source_name="${1}"
local target_name="${2}"
declare -n source_ref="$source_name"
declare -n target_ref="$target_name"
for k in "${!source_ref[@]}"; do
# log_debug "$k: ${source_ref[$k]}"
target_ref[$k]=${source_ref[$k]}
done
unset -n source_ref
unset -n target_ref
}
shlibs.array.sort() {
local -n -r input_array_ref="$1"
local -n output_array_ref="$2"
shift 2
IFS=$'\n' output_array_ref=($(sort $@ <<<"${input_array_ref[*]}"))
unset IFS
}
shlibs.array.sort.unique() {
# sorts param --unique is not available on every os, e.g. alpine
shlibs.array.sort $1 $2 -u
}