Using the value of one variable to name another variable (in bash)

Hello all,

I'm working on a script, and as part of it, I'm trying to create a loop that will run through a stored piece of information a certain number of times pulling out information, and each time create a variable with a unique name that will store that information. I'm sure it's a simple syntax problem, but I've gone through it several different ways and I can't seem to find my mistake.

(05:15:30\[ddecosta@S.Man)
[~/bin]$ cat x
#!/usr/bin/bash

#Define Colours
red='\e[0;31m'
nc='\e[0m'

#Make certain that we have something to check
if [ -z $1 ];then
echo -e " ${red}You Must Specifiy what MOD you wish to check${nc}"
exit 1
fi

#Get QPSK info
lq=`listQpsk $1`
echo "Counting Number of DeMODS"
#Establish number of DeMods on QPSK 
num_of_mods=`echo "$lq"|awk '{print $3}'|grep -cw [1-9]`
#get current count for each DeMOD
modseq="1"
until [[ $modseq -gt $num_of_mods ]];do
count"$modseq"=`echo "$lq"|grep -w $modseq|awk '{print $5}'`
echo "$count"$modseq""
modseq=$(($modseq+1))
done

(05:15:17\[ddecosta@S.Man)
[~/bin]$ ./x 42
Counting Number of DeMODS
./x: line 40: count1=824: command not found
1
./x: line 40: count2=130: command not found
2
./x: line 40: count3=865: command not found
3
./x: line 40: count4=829: command not found
4
./x: line 40: count5=948: command not found
5
./x: line 40: count6=611: command not found
6
./x: line 40: count7=666: command not found
7
./x: line 40: count8=967: command not found
8


(05:15:36\[ddecosta@S.Man)
[~/bin]$ 

Just so you can see what the listQpsk value is:

(05:15:01\[ddecosta@S.Man)
[~/bin]$ listQpsk 42
 ID QPSK Name           Demod   IS2W    SignOn  % SignOn
--- ------------------  -----  -----  --------  --------
 42 SMANHUBAQPSK3          -       0         0        -
 42 SMANHUBAQPSK3          1     988       824        83
 42 SMANHUBAQPSK3          2     169       130        76
 42 SMANHUBAQPSK3          3    1014       865        85
 42 SMANHUBAQPSK3          4     971       829        85
 42 SMANHUBAQPSK3          5    1129       948        83
 42 SMANHUBAQPSK3          6     756       611        80
 42 SMANHUBAQPSK3          7     796       666        83
 42 SMANHUBAQPSK3          8    1201       967        80
--- ------------------  -----  -----  --------  --------
    Total (IS2W, signed on)     7024      5840        83
Jun 18 05:15:17 - listQpsk Ended.

All I want to do is set the 5th column of each line numbered 1-whatever as it's own variable (which will later be used to do some comparisons).

Thanks.

Well, you're using bash, and that has support for arrays (although older versions might not). Second, you can create variables using eval:

let x=10
eval x_$x=12
set|grep ^x

I appreciate the thought. I understand the idea of arrays, but I'm not really at the point where I can use them.

I'm trying to understand the eval command, but I'm not sure I'm getting it. I read through the man page and some examples on line...but it's not sinking in. But I've been up all night doing a maintenance, so I doubt I could understand much of anything right now.

About eval:

The bash shell process the command line by expanding variables and other "magic". After this is done, the line is now ready for processing by the command:

eval x_10=12

The eval simply executes the arguments as if those arguments had been the command itself. So bash executes:

x_10=12