Is it possible to define variable that is called for example machine1 as machine$counter ( while counter=1 ) ?
For example, I created the /tmp/config.txt
file and set the machine1 as array:
$ more /tmp/config.txt
machine1=( linux_server critical 1.1.1.1 )
machine2=( linux_server critical 1.1.1.2 )
.
.
Then I created the following simple script to read the /tmp/config.txt
. And I try to print the machine array as the following:
$ more read.config.bash
#!/bin/bash
source /tmp/config.txt
counter=1
echo ${machine$counter[0]}
echo ${machine$counter[1]}
echo ${machine$counter[2]}
.
.
But when I run the script, I get:
$ ./read.config.bash
./read.config.bash: line 6: ${machine$counter[0]}: bad substitution
./read.config.bash: line 7: ${machine$counter[1]}: bad substitution
./read.config.bash: line 8: ${machine$counter[2]}: bad substitution
What is the solution for this problem ?