Created
October 9, 2017 22:42
-
-
Save pkutzner/678155223bfd7720fd584171e6961877 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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