mirror of
https://github.com/octoleo/hosts.git
synced 2025-02-14 08:10:24 +00:00
Use improved _contains()
.
This commit is contained in:
parent
f0ebb08cd4
commit
9bf7f782c9
24
hosts
24
hosts
@ -255,7 +255,7 @@ _main() {
|
|||||||
_load_commands
|
_load_commands
|
||||||
|
|
||||||
# If the command is defined, run it, otherwise return an error.
|
# If the command is defined, run it, otherwise return an error.
|
||||||
if _contains "${_CMD}" "${_DEFINED_COMMANDS[*]:-}"
|
if _contains "${_CMD}" "${_DEFINED_COMMANDS[@]:-}"
|
||||||
then
|
then
|
||||||
# Pass all comment arguments to the program except for the first ($0).
|
# Pass all comment arguments to the program except for the first ($0).
|
||||||
"${_CMD}" "${_COMMAND_PARAMETERS[@]:-}"
|
"${_CMD}" "${_COMMAND_PARAMETERS[@]:-}"
|
||||||
@ -301,22 +301,26 @@ _command_exists() {
|
|||||||
# _contains()
|
# _contains()
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# _contains "$item" "${list[*]}"
|
# _contains "${item}" "${list[@]}"
|
||||||
#
|
#
|
||||||
# Exit Status:
|
# Returns:
|
||||||
# 0 If the item is included in the list.
|
# 0 If the item is included in the list.
|
||||||
# 1 If not.
|
# 1 If not.
|
||||||
_contains() {
|
_contains() {
|
||||||
local _test_list=(${*:2})
|
local _query="${1:-}"
|
||||||
for __test_element in "${_test_list[@]:-}"
|
shift
|
||||||
do
|
|
||||||
_debug printf "_contains() \${__test_element}: %s\\n" "${__test_element}"
|
if [[ -z "${_query}" ]] ||
|
||||||
if [[ "${__test_element}" == "${1}" ]]
|
[[ -z "${*:-}" ]]
|
||||||
then
|
then
|
||||||
_debug printf "_contains() match: %s\\n" "${1}"
|
return 1
|
||||||
return 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
for __element in "${@}"
|
||||||
|
do
|
||||||
|
[[ "${__element}" == "${_query}" ]] && return 0
|
||||||
done
|
done
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user