Skip to content
Snippets Groups Projects
Commit 87114b7a authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

Improve environment variable checker function

parent 39101098
No related branches found
No related tags found
No related merge requests found
...@@ -73,50 +73,46 @@ log_error() { ...@@ -73,50 +73,46 @@ log_error() {
} }
# Checks a given environment variable is set (non-zero size) # Checks just if the variable is defined and has non-zero length
check_env() { check_defined() {
if [ -z "${1+abc}" ]; then if [ -z "${!1+abc}" ]; then
log_error "Variable ${1} is undefined - aborting..."; log_error "Variable ${1} is undefined - aborting...";
exit 1 exit 1
else elif [ -z "${!1}" ]; then
log_info "${1}=${!1}"; log_error "Variable ${1} is zero-length - aborting...";
exit 1
fi fi
} }
# Checks a given environment variable is set (non-zero size)
check_env() {
check_defined "${1}"
log_info "${1}=${!1}"
}
# Checks a given environment variable array is set (non-zero size) # Checks a given environment variable array is set (non-zero size)
check_array_env() { check_array_env() {
if [ -z "${1+abc}" ]; then check_defined "${1}"
log_error "Variable ${1} is undefined - aborting..."; for i in "${!1[@]}"; do
exit 1 log_info "${1}[${i}]=${!1[${i}]}";
else done
for i in "${!foo[@]}"; do
log_info "${1}[${i}]=${!1[${i}]}";
done
fi
} }
# Exports a given environment variable, verbosely # Exports a given environment variable, verbosely
export_env() { export_env() {
if [ -z "${1+abc}" ]; then check_defined "${1}"
log_error "Variable ${1} is undefined - aborting..."; export ${1}
exit 1 log_info "export ${1}=${!1}"
else
export ${1}
log_info "export ${1}=${!1}";
fi
} }
# Checks a given environment variable is set (non-zero size) # Checks a given environment variable is set (non-zero size)
check_pass() { check_pass() {
if [ -z "${1+abc}" ]; then check_defined "${1}"
log_error "Variable ${1} is undefined - aborting..."; log_info "${1}=********"
exit 1
else
log_info "${1}=********";
fi
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment