I`m trying to create environment variables via script if the variable does not exist.
What I am doing for this is the following:
local env_variable_name="VARIABLE_"$id
if [[ -z "${env_variable_name}" ]]; then
break
else
local env_var_value=$(generate_value $some_argument)
export "$env_variable_name"="${env_var_value}"
fi
My goal is to create an environment variable, for which I can choose my own dynamic name. If the script is fired again, I want to prevent the script to overwrite the value that is initially set.
If I run the script with "source" it works as expected. The environment variable i set and persisted. If I run the script again, the value of the environment variable will be overwritten. The right way is to check if the environment variable exists by its name, but i cant find a way to do this without knowing how the variable name and hardcoding it into the script.