Anup Anup - 4 years ago 129
Bash Question

How to create new variables using counters?

Below is my code snippet,

counters=1
details='AAA BBB CCC'
details_$counters=$details
echo $details_1


Result expected

AAA BBB CCC

Answer Source

Use eval for variable name interpolation.

x="1"
eval "y_$x='hello world'"
echo $y_1 # outputs "hello world"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download