Skip to content

Instantly share code, notes, and snippets.

@kallookoo
Last active November 8, 2023 17:44
Show Gist options
  • Save kallookoo/72ed031a07d78e293a7bebe2f901a215 to your computer and use it in GitHub Desktop.
Save kallookoo/72ed031a07d78e293a7bebe2f901a215 to your computer and use it in GitHub Desktop.
Bash function to check value in array
# Usage: in_array "string" "${array[@]}"
function in_array() {
if [[ $# -gt 2 ]] && [[ "$(printf '%s\n' "$@" | grep -cx -- "$1")" -gt "1" ]]; then
return 0
fi
return 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment