This question does not answer my question.
I have a script that checks the existence of specific environment variables and prints them with their values. Now I want to mask the values of password variables (containing SECRET
, PW
, PASSWORD
, KEY
in its name, e.g. CLIENT_SECRET
) with ****
.
Currently I have a script like this:
expected_env_vars=("CLIENT_ID" "CLIENT_SECRET" "BACKEND_KEY" "BACKEND_NAME")
suppress_env_vars_with_substring=("SECRET" "PASSWORD" "PW" "KEY")
for env_var in "${expected_env_vars[@]}"; do
if [[ -z "${!env_var}" ]]; then
echo "Environment variable \"$env_var\" not defined"
exit 1
else
# Perform check if an element of $suppress_env_vars_with_substring is substring of $env_var
echo "$env_var=${!env_var}...OK"
fi
done
Question
How to check if an array element is substring of a string?