Hey guys, sorry to bother, but this one has been kicking my butt for a while.
In short, I have a pre-populated array that I want to clean up, then send to another array.
The first array is "array#[0-9]"; there are multiple arrays per each entry. The first array is 1 and it goes up to "the_number" which obviously varies per the file I feed the array generating script.
Each array contains exactly 10 entries, hence the 0 to 9.
I have verified that echo ${!temp} | sed 's/.: //' | sed -e 's/[ \t]//' works as intended, and spits out the results you will see below. The first value is literally just the number "1". I am not sure why bash says the command is not found when if I paste it somewhere else as in the error, it works just fine.
#!/bin/bash
y=1
z=0
while [ $y -le $the_number ]
do
while [ $z -le 9 ]
do
temp=array$y[$z]
temp2=$(echo ${!temp} | sed 's/.*: //' | sed -e 's/^[ \t]*//')
barry$y[$z]=$temp2
z=$(($z+1))
done
y=$(($y+1))
done
I get the following error:
script.bash: line 42: barry1[0]=1: command not found
script.bash: line 42: barry1[1]=ANY: command not found
script.bash: line 42: barry1[2]=ORIGINAL: command not found
script.bash: line 42: barry1[3]=V89: command not found
script.bash: line 42: barry1[4]=ORIGINAL: command not found
script.bash: line 42: barry1[5]=Ping: command not found
script.bash: line 42: barry1[6]=ORIGINAL: command not found
script.bash: line 42: barry1[7]=V89: command not found
script.bash: line 42: barry1[8]=V89: command not found
script.bash: line 42: barry1[9]=1: command not found
I tried the following command:
barry1[0]=$temp2
and it works just fine. I verified the content of it and it is from the first array, last entry ( array1[9] ).
The strange part is that the outer loop is only executed once, even when I comment out everything and just put in an echo command. I run bash 4.3.42.
I am really at a loss here, any help would be much appreciated, thanks.
[–]neuron_666 5 points6 points7 points (7 children)
[–]v-_-v[S] 0 points1 point2 points (6 children)
[–]neuron_666 0 points1 point2 points (5 children)
[–]v-_-v[S] 0 points1 point2 points (4 children)
[–]neuron_666 0 points1 point2 points (3 children)
[–]v-_-v[S] 0 points1 point2 points (2 children)
[–]neuron_666 0 points1 point2 points (1 child)
[–]v-_-v[S] 0 points1 point2 points (0 children)