INNER CODE UNIT · Shell

array_contains

gruntwork-io/bash-commons · modules/bash-commons/src/array.sh:4

function array_contains {
  local -r needle="$1"
  shift
  local -ra haystack=("$@")

  local item
  for item in "${haystack[@]}"; do
    if [[ "$item" == "$needle" ]]; then
      return 0
    fi
  done

  return 1
}

# Splits the given $string into an array of elements based on the given $separator
#
# Examples:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…