Seems like you have some problems with your ${team_two[*]}
& ${team_two[k1]}
arrays or you've messed with the separation characters in the special variable $IFS
. You can turn the Bash debugging on by adding a set -x
before you enter the outer for loop. And then disable it afterwards with a set +x
, to gain further insights.
set -x
... for loop block ...
set +x
Example
When I run your code through Bash in this manner I get the following output:
$ bash -x for.bash
++ seq 1 5
+ for i1 in '`seq 1 5`'
+ num1=2
++ seq 2 5
+ for k1 in '`seq $num1 5`'
+ ky1=_
+ pair_score[$ky1]=1
+ for k1 in '`seq $num1 5`'
+ ky1=_
+ pair_score[$ky1]=2
+ for k1 in '`seq $num1 5`'
+ ky1=_
+ pair_score[$ky1]=3
+ for k1 in '`seq $num1 5`'
+ ky1=_
+ pair_score[$ky1]=4
+ for i1 in '`seq 1 5`'
+ num1=3
++ seq 3 5
+ for k1 in '`seq $num1 5`'
+ ky1=_
+ pair_score[$ky1]=5
+ for k1 in '`seq $num1 5`'
+ ky1=_
+ pair_score[$ky1]=6
+ for k1 in '`seq $num1 5`'
+ ky1=_
+ pair_score[$ky1]=7
+ for i1 in '`seq 1 5`'
+ num1=4
++ seq 4 5
+ for k1 in '`seq $num1 5`'
+ ky1=_
+ pair_score[$ky1]=8
+ for k1 in '`seq $num1 5`'
+ ky1=_
+ pair_score[$ky1]=9
+ for i1 in '`seq 1 5`'
+ num1=5
++ seq 5 5
+ for k1 in '`seq $num1 5`'
+ ky1=_
+ pair_score[$ky1]=10
+ for i1 in '`seq 1 5`'
+ num1=6
++ seq 6 5
Edit #1
After further updates it would appear you've reset $IFS
. Typically you'll want to save $IFS
to an secondary variable prior to reseting it, and the revert it later on back to it's original value.
IFSOLD=$IFS
IFS=,
... do IFS , stuff here ...
IFS=$IFSOLD
IFS
If you try these examples they might help shed additional light on to the impact $IFS
can play when used within a script.
Say I have the following variable:
$ var="1,2,3,4,5"
Now let's parse it and print the first variable, $c1
:
$ IFS=',' read -r c1 c2 c3 c4 c5 <<< "$var"
$ echo "$c1"
1
However if we changed our $IFS
to a space.
$ IFS=' ' read -r c1 c2 c3 c4 c5 <<< "$var"
$ echo "$c1"
1,2,3,4,5
So in the second example, we've configured the read
command via $IFS
to split on spaces, rather than commas.