Last active
November 8, 2023 17:44
-
-
Save kallookoo/72ed031a07d78e293a7bebe2f901a215 to your computer and use it in GitHub Desktop.
Bash function to check value in array
This file contains 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
# 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