Skip to content

Instantly share code, notes, and snippets.

@pkutzner
Created October 9, 2017 22:42
Show Gist options
  • Save pkutzner/678155223bfd7720fd584171e6961877 to your computer and use it in GitHub Desktop.
Save pkutzner/678155223bfd7720fd584171e6961877 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -u
THELIST=( 'one' 'two' 'three' 'four' 'five' 'six' 'seven' 'eight' 'nine' 'ten' )
THEITEM='twelve'
declare -a EXTLIST=()
EXTLIST=( 'eleven' 'twelve' )
if [[ ${#EXTLIST[@]} -gt 0 ]]; then
THELIST+=( "${EXTLIST[@]}" )
fi
contains() {
echo "The list: $1"
[[ "$1" =~ (^|[[:space:]])"$2"($|[[:space:]]) ]] && return 0 || return 1
}
if contains "${THELIST[*]}" "$THEITEM"; then
echo "\$THELIST contains ${THEITEM}"
else
echo "\$THELIST doesn't contain ${THEITEM}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment