Is there a way to test whether an array contains a specified element?
e.g., something like:
array=(one two three)
if [ "one" in ${array} ]; then
...
fi
Is there a way to test whether an array contains a specified element?
e.g., something like:
array=(one two three)
if [ "one" in ${array} ]; then
...
fi
A nice and elegant version of the above.
A for loop will do the trick.
I got an function 'contains' in my .bashrc-file:
It works well with an array:
But doesn't need an array:
if you just want to check whether an element is in array, another approach
If that's ugly, you could hide it away in a function.
Try this: