How to dynamically add and use variables in the shell… here is a solution to the problem.
How to dynamically add and use variables in the shell
For example, I have a file like this:
abc
def
ghi
Now, I want to use a Linux shell script to set some variables based on this file. I need to set the following variable to:
export abc=abc111
export def=def111
export ghi=ghi111
As you can see, the variable names are also retrieved from the list file. Thank you.
Solution
while read var; do
export $var=${var}111
done < vars.txt