Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Last active January 2, 2016 07:29
Show Gist options
  • Save coderofsalvation/8270452 to your computer and use it in GitHub Desktop.
Save coderofsalvation/8270452 to your computer and use it in GitHub Desktop.
inarray() and isarray() functions for bash (to check whether value exist)
# look for a value in an array, returns 0 on success, 1 otherwise
# Usage: in_array "$needle" "${haystack[@]}"
inarray()
{
[ -z "$1" ] && return 1
if [ -n "$BASH" ]; then
_inarray_var_needle="$1"
shift
for element
do
[ X"$element" != X"$_inarray_var_needle" ] || return 0
done
fi
return 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment