-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_slice
More file actions
executable file
·93 lines (91 loc) · 1.86 KB
/
array_slice
File metadata and controls
executable file
·93 lines (91 loc) · 1.86 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env bash
declare -i start=0; unset start; declare -i start
declare -i end=0; unset end; declare -i end
declare f_isLength='false'
# Is end of range exclusive?
declare f_isExclusive='true'
declare -n opt1=start opt2=end
while [[ -n "${1+x}" ]]; do
case "$1" in
(-h | --help)
# show_help
exit 1
;;
(-v | --version)
# show_version
exit 1
;;
(-e | --exclusive)
declare -r f_isExclusive='true'
shift
;;
(-i | --inclusive)
declare -r f_isExclusive='false'
shift
;;
(-l | --length)
declare -r f_isLength='true'
if [[ "$1" =~ ^--length=(-?[[:digit:]]+)$ ]]; then
declare -i end="${BASH_REMATCH[1]}"
elif [[ "$2" =~ ^-?[[:digit:]]+$ ]] && [[ -z "${end+x}" ]]; then
declare -i end="$2"
shift
fi
shift
;;
(--)
shift
break
;;
([-+]?[[:digit:]]+)
if [[ -n "${opt1+x}" ]]; then
if [[ -n "${opt2+x}" ]]; then
break
else
opt2="$1"
fi
else
opt1="$1"
fi
shift
;;
(*) break ;;
esac
done
declare -ri totalLength=$#
if eval "$f_isLength" && ((end < 0)); then
# TODO: Length out of bounds
exit 1
fi
# Convert negative indices
((start += start < 0 ? totalLength : 0, end += end < 0 ? totalLength : 0))
# Force exclusive end
if ! eval "$f_isLength" && ! eval "$f_isExclusive"; then ((end++)); fi
declare -ri start end
if ((start >= totalLength)); then
# TODO: Start out of bounds
exit 1
elif eval "$f_isLength" && ((end > totalLength)); then
# TODO: Length/end out of bounds
exit 1
elif ! eval "$f_isLength" && ((end > totalLength)); then
# TODO: End out of bounds
exit 1
fi
if ((start = 0 && end ))
declare -a inputArray=("$@")
for ((i = 1; i <= start; i++)); do
done
while (($# > 0)) && shift; do
if [ "$1" = "$toRemove" ]; then
if eval "$f_all"; then
continue
elif shift; then
result+=("$@")
fi
break
fi
result+=("$1")
done
echo "${result[@]}"
exit