imapollo
imapollo

Reputation: 387

How to add and use variables in shell dynamically

For example, I have a file look as follows:

abc
def
ghi

Now, I want to use a Linux shell script to set some variables according to this file. I need the following variables to be set something like:

export abc=abc111
export def=def111
export ghi=ghi111

As you can see that the variable names are retrieved from list file as well. Thanks.

Upvotes: 3

Views: 120

Answers (1)

John Kugelman
John Kugelman

Reputation: 362157

while read var; do
    export $var=${var}111
done < vars.txt

Upvotes: 4

Related Questions