'Exporting multiple variables in a for loop

I am having trouble exporting multiple env variables in a for loop of a bash script.

The full script looks something like:

IFS_old="$IFS"
IFS=';'
test_data="secret1='data1';secret2='data2';secret3='data3'"
for secret in $test_data
do
    eval "export $secret"
done
IFS="$IFS_old"

So the input string consists of variables and their values separated by a semicolon. I loop through it and want to export each of them; however, the variables that get exported have "null" values.

I also tried composing a full command string in a separate variable, and executing it both via bash -c "$command" and eval "$command" statements, but it didn't work.

Can you please help me figure out what's wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source