-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_join
More file actions
executable file
·73 lines (67 loc) · 1.49 KB
/
array_join
File metadata and controls
executable file
·73 lines (67 loc) · 1.49 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env bash
##region########################################### HELP & VERSION ###########################################
_show_help() {
cat << __EOF__
Join each value in the array/list with the separator. Similar to Bash's array[*], but allows for a separator of multiple characters.
Usage: $0 SEPARATOR VAL1 VAL2...
or: $0 (-s | --separator) SEPARATOR VAL1 VAL2...
or: $0 --help
or: $0 --version
Options:
-h, --help: Shows this help text.
-v, --version: Shows version info.
-s, --separator SEPARATOR: The string placed between each entry. Can be an empty string.
__EOF__
}
_show_version() {
cat << __EOF__
$0 3.0.0
Copyright (C) 2025 Justin Morris
__EOF__
}
##endregion######################################## HELP & VERSION ###########################################
declare separator=
while [[ "$1" =~ ^- ]]; do
case "$1" in
(-h | --help)
_show_help
exit
;;
(-v | --version)
_show_version
exit
;;
(--)
shift
break
;;
(-s | --separator)
shift
declare -r separator="$1"
shift
;;
(*)
# if [[ -n "${opt1+x}" ]]; then
# if [[ -n "${opt2+x}" ]]; then
# if [[ -n "${opt3+x}" ]]; then
# exit 1
# else
# opt3="$1"
# fi
# else
# opt2="$1"
# fi
# else
# opt1="$1"
# fi
# shift
break
;;
esac
done
if declare -r separator="$1" && ! shift; then exit 1; fi
result="$1"
while (($# > 0)) && shift; do result+="$separator$1"; done
# TODO: Option to enable escape sequences
echo -nE "$result"
exit