Created
November 26, 2013 19:22
-
-
Save pinktrink/7664466 to your computer and use it in GitHub Desktop.
Determine whether a value exists in an array in Bash. This only works if the array has values which do not have spaces in them.
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
array=(a b c d e) | |
search=d | |
if [[ ' '${array[*]}' ' =~ ' '$search' ' ]]; then | |
echo 'It exists!' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment