-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_includes
More file actions
executable file
·37 lines (36 loc) · 1.31 KB
/
array_includes
File metadata and controls
executable file
·37 lines (36 loc) · 1.31 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
#!/usr/bin/env bash
if [ "$1" = '--help' ]; then
exit 1
elif [ "$1" = '--version' ]; then
exit 1
fi
##region########################################### GET PATH, DIR, & NAME ###########################################
# readonly MY_PATH=$(realpath "$0")
# MY_DIR=''
# MY_NAME=''
# if [[ "$MY_PATH" =~ ^(.*)/([^/]+)$ ]]; then
# readonly MY_DIR="${BASH_REMATCH[1]}" MY_NAME="${BASH_REMATCH[2]}"
# else
# readonly MY_DIR="$HOME" MY_NAME="$0"
# echo "$MY_NAME: Failed to get dir" 1>&2
# exit 1
# fi
##endregion######################################## GET PATH, DIR, & NAME ###########################################
if [[ "$1" =~ ^(declare|local|readonly)([[:blank:]]-([[:alpha:]]+)[[:blank:]])[^[:blank:]=]+=\((.*)\)$ ]] && brm=("${BASH_REMATCH[2]}" "${BASH_REMATCH[4]}") && [[ "${BASH_REMATCH[3]}" =~ 'a' ]]; then
# # shellcheck disable=SC2086
# declare ${brm[0]} values=(${brm[1]})
declare +a +A execLine="declare -a values=()"
$execLine
mapfile -t values< <(echo -nE "${brm[1]}" | sed -E 's/(\[[[:digit:]]+\]=)?('$'\"([^\"]*)\"|\'([^\']*)\')[[:blank:]]?/''\3\4''\n''/g')
if ! shift; then exit 255; fi
for arg in "$@"; do
if array_includes "$arg" "${values[@]}"; then exit 0; fi
done
exit 2
fi
declare value="$1"
if ! shift; then exit 255; fi
for arg in "$@"; do
if [ "$value" = "$arg" ]; then exit 0; fi
done
exit "${ec:-1}"