From 3ae961c4b9120fd84e1656acfd9091a34708ec0f Mon Sep 17 00:00:00 2001 From: deajan Date: Fri, 21 Oct 2016 12:37:38 +0200 Subject: [PATCH] Added arrayContains function --- dev/ofunctions.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dev/ofunctions.sh b/dev/ofunctions.sh index a3a5ab9..93a9884 100644 --- a/dev/ofunctions.sh +++ b/dev/ofunctions.sh @@ -1,6 +1,6 @@ #### MINIMAL-FUNCTION-SET BEGIN #### -## FUNC_BUILD=2016101901 +## FUNC_BUILD=2016102101 ## BEGIN Generic bash functions written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr ## To use in a program, define the following variables: @@ -922,6 +922,21 @@ function urlDecode { printf '%b' "${urlEncoded//%/\\x}" } +## Modified version of http://stackoverflow.com/a/8574392 +## Usage: arrayContains "needle" "${haystack[@]}" +arrayContains () { + local e + + if [ "$2" == "" ]; then + echo 1 && return 1 + fi + + for e in "${@:2}"; do + [[ "$e" == "$1" ]] && echo 0 && return 0 + done + echo 1 && return 1 +} + function GetLocalOS { __CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG