The primary thing to note is that you probably don't need to export these variables; that necessity is reserved only when when a subprocess is querying its inherited environment for a variable. Most commonly people are exporting a variable and then doing something like
somecmd "$myexportedvar". Your shell is expanding
somecmd ever sees it.
If you really do need to export these for a subprocess to pull from its environment:
while IFS= read -r line; do
if [[ $line == *=* && $line != #* ]]; then
IFS== read -r var val <<<"$line"
printf -v "$var" '%s' "$val"
done < "$HOME/variables.txt"
this loop checks that the line is an assignment (kinda) and that the first character is not a comment hash. makes the effort a little more robust, but just barely. see the two options below instead, for handling this more carefully.
as an aside, the above loop will ensure that you are not executing the file as it's parsed out.
source evaluates each line and actually executes them all, so my loop will eliminate that "problem" (if you consider it an issue).
Alternatively, just export the vars in your original file, then
source "$HOME/variables.txt" and the work is already done.
you may want to just use
set -a; . "$HOME"/variables.txt; set +a. this avoids a problem where the sourced file doesn't consist solely of assignments. the parsing loop above can result in false-positives. read
help set to understand what it's doing.
Also, Don't Read Lines With For and Use More Quotes