Created
March 2, 2018 13:26
-
-
Save sldenazis/0e7dc94b9dc25e8f0e840c96c99f1ace to your computer and use it in GitHub Desktop.
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
function is_in_array { | |
# Return 0 if element is found, 1 if not | |
if [[ $# -lt 2 ]]; then | |
echo "Usage: $FUNCNAME string array" >&2 | |
else | |
local element=${1} i="" | |
shift | |
declare -a list=$@ | |
for i in ${list[@]}; do | |
if [[ $i == $element ]]; then | |
return 0 | |
fi | |
done | |
fi | |
return 1 | |
} | |
function check_settings { | |
# Receive an array of vars and fails if one is unset | |
local required_settings=$@ | |
local setting="" return_code=0 | |
for setting in ${required_settings[@]}; do | |
if [[ -z "${!setting}" ]]; then | |
echo "Error! ${setting} must be specified!" >&2 | |
return_code=1 | |
fi | |
done | |
return ${return_code} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment