Here’s an example script that doesn’t work the way I expect:
#!/bin/bash
for dynamic in a b c; do
myvar=$dynamic
export $myvar="hi"
echo $(eval "$myvar")
echo $dynamic
done
I want the output would be:
hi
a
hi
b
hi
c
Any ideas? I’m willing to stray away from this method, but I definitely want to be able to create a variable named from the output of an algorithm. In this case it’s just a for loop.
It’s not entirely clear that this is what you’re looking for, but I think you want something like:
#!/bin/sh a=A b=B c=C for i in a b c; do eval $i=value_$i eval echo \$$i done echo $a # Prints "value_a"