Skip to content

Instantly share code, notes, and snippets.

@pinktrink
Created November 26, 2013 19:22
Show Gist options
  • Save pinktrink/7664466 to your computer and use it in GitHub Desktop.
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.
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