I'm checking whether or not environment variables are set.
This gives me exactly what I want in the singular:
: ${API_KEY:?`echo "Need to set API_KEY"`}
However, when I extract a function to loop over a collection of variables, things don't work like I'd expect.
function check_env_for {
: ${$1:?`echo "Need to set $1 non-empty"`}
}
check_env_for API_KEY
breaks, returning:
-bash: ${$1:?`echo "Need to set $1 non-empty"`}: bad substitution
While a solution is appreciated, what core shell fundamentals am I likely missing?