Last active
March 15, 2025 10:55
-
-
Save kallookoo/72ed031a07d78e293a7bebe2f901a215 to your computer and use it in GitHub Desktop.
Shell function to check if an element exists in an array
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
# in_array - Check if an element exists in an array | |
# Usage: in_array "needle" "${array[@]}" | |
# Example: in_array "apple" "${fruits[@]}" | |
in_array() { | |
[ $# -gt 1 ] && [ "$(printf '%s\n' "$@" | grep -cx -- "$1")" -gt "1" ] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment