Skip to content

Instantly share code, notes, and snippets.

@brimston3
Created July 14, 2014 18:03
Show Gist options
  • Save brimston3/c63b0fdf2564bc28e2e1 to your computer and use it in GitHub Desktop.
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.
#!/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
@brimston3
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment