check_envs(var) {
  local command="$2"

  if [[ -z "${!env_var}" ]]; then
    read -rp "Enter value for $env_var: " "${env_var}"
    export "$env_var=${!env_var}" #Export the variable to be accessible by child processes
  fi

  if [[ -n "${!env_var}" ]]; then
    eval "$command"
  else
    echo "Environment variable $env_var is not set. Command not executed."
  fi
}

# Example usage:
# run_with_env MY_API_KEY "curl -H \"Authorization: Bearer $MY_API_KEY\" https://api.example.com"
# run_with_env DATABASE_URL "psql $DATABASE_URL -c 'SELECT * FROM users;'"
