Created
July 14, 2014 18:03
-
-
Save brimston3/c63b0fdf2564bc28e2e1 to your computer and use it in GitHub Desktop.
A function to test if contents are in array. I probably swiped this from S.O. with minor alterations.
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
#!/bin/bash | |
function contains() { | |
local n=$# | |
local value=${!n} | |
for ((i=1;i < $#;i++)) { | |
if [ "${!i}" == "${value}" ]; then | |
return 0 | |
fi | |
} | |
return 1 | |
} | |
#### Example usage #### | |
if contains "${preds_right[@]}" "$ver_left" ; then | |
pred_common="$ver_left" | |
break | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yep, totally from S.O. #3685970
contains function retains CC-BY-SA 3.0. (it's literally 12 lines though, not sure how reasonable copyright is here, but I've BY'd anyway)