Reputation: 499
I am trying to execute the following code for 2-iterations but for first iteration, I am getting wrong result.
I run the following command: ./test.sh 2
# File name: test.sh
Y=`echo "$1 - 1" | bc -l`
dsp=(0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 )
file1=(0 0 0 0 0 -3 -3 -3 -3 -3 -6 -6 -6 -6 -6 )
for i in {0..$Y}
do
a=$dsp[$i]
e=$file1[$i]
echo "set_property LOC DSP48E2_X0Y$(echo "18*${i}+ 0 + $a" | bc) [get_cells {name[$(echo "13*${i}+0 + $e" | bc)].dut}];"
done
Expected result:
set_property LOC DSP48E2_X0Y0 [get_cells {name[0].dut}]
set_property LOC DSP48E2_X0Y18 [get_cells {name[13].dut}]
But instead I am getting an error:
(standard_in) 2: syntax error
(standard_in) 2: syntax error
set_property LOC DSP48E2_X0Y [get_cells {name[].dut}];
set_property LOC DSP48E2_X0Y18 [get_cells {name[13].dut}];
Upvotes: 0
Views: 37
Reputation: 361565
Variables don't work inside of curly braces. To loop over a range of numbers use a C-style for
loop:
for ((i = 0; i < Y; i++)); do
...
done
You also don't have to use bc
. Bash can do integer arithmetic natively with $((...))
.
Y=$(($1 - 1))
...
echo "set_property LOC DSP48E2_X0Y$((18*i+a)) [get_cells {name[$((13*i+e))].dut}];"
Also, accessing array elements requires curly braces:
a=${dsp[$i]}
e=${file1[$i]}
Upvotes: 1