From 712c340cddd5ae75b3dc10066b99e40f79eab40e Mon Sep 17 00:00:00 2001 From: belliash Date: Sun, 1 Jan 2012 12:28:20 +0100 Subject: [PATCH] implement hasElement() --- libraries/common | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libraries/common b/libraries/common index cf0c367..c06162c 100644 --- a/libraries/common +++ b/libraries/common @@ -32,6 +32,20 @@ function die() { exit ${2} } +#------------------------------------------------------------------------------- +# Checks whether a defined variable contain specified element or not +# Parameters: %variable% %element% +#------------------------------------------------------------------------------- +function hasElement() { + local NEEDLE=${1} + shift + local X + for X in "${@}"; do + [ "${X}" = "${NEEDLE}" ] && return 0 + done + return 1 +} + #------------------------------------------------------------------------------- # Checks whether a supplied variable is defined or not # Parameters: %variable%