Code compliance on ArrayContains

This commit is contained in:
deajan 2016-12-06 23:24:02 +01:00
parent 9735a83b35
commit 226bf33e29
1 changed files with 13 additions and 9 deletions

View File

@ -1,7 +1,7 @@
#### MINIMAL-FUNCTION-SET BEGIN #### #### MINIMAL-FUNCTION-SET BEGIN ####
_OFUNCTIONS_VERSION=2.0 _OFUNCTIONS_VERSION=2.0
_OFUNCTIONS_BUILD=2016120401 _OFUNCTIONS_BUILD=2016120601
## BEGIN Generic bash functions written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr ## 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: ## To use in a program, define the following variables:
@ -1006,17 +1006,21 @@ function urlDecode {
## Modified version of http://stackoverflow.com/a/8574392 ## Modified version of http://stackoverflow.com/a/8574392
## Usage: arrayContains "needle" "${haystack[@]}" ## Usage: arrayContains "needle" "${haystack[@]}"
arrayContains () { function ArrayContains () {
local needle="${1}"
local haystack="${2}"
local e local e
if [ "$2" == "" ]; then if [ "$needle" != "" ] && [ "$haystack" != "" ]; then
echo 0 && return 0 for e in "${@:2}"; do
if [ "$e" == "$needle" ]; then
echo 1
return
fi
done
fi fi
echo 0
for e in "${@:2}"; do return
[[ "$e" == "$1" ]] && echo 1 && return 1
done
echo 0 && return 0
} }
function GetLocalOS { function GetLocalOS {