Reputation: 631
I would like to set a variable which name is stored in a file (is an output of a sed executed earlier)
the file would look like:
py1
so setting our variable would be like: set cat file
=value
but echoing $py1
gives me nothing.
Is that possible with bash version 2.05?
Upvotes: 2
Views: 1379
Reputation: 149756
Use eval
:
eval "$(cat file)=value"
Update: The command substitution $(cat file)
can be replaced by the equivalent but faster $(< file)
.
Upvotes: 2
Reputation: 25599
This is the "preferred" way to do it (bash) without using cat
or eval
declare $(<file)=value
Upvotes: 3