在bash中使用数组,example:数组之间的赋值需要用for循环逐个拷贝
#!/bin/bash
#declare -i c=$1
echo "Start Read_GT_POS ..."
a=1
c=8
fpga_addr0=0xc0400000
fpga_addr1=0xc0400008
param_n=$#
echo input_number:${param_n}
echo "note:param1:1~8 represent F1~F8"
declare -a my_array_f=(0 0 0 0 0 0 0 0 0 0 0 0)
declare -a my_array_f1=(0 0 0 0 0 0 0 0 0 0 0 0)
declare -a my_array_f2=(1 1 1 0 0 0 0 0 0 0 0 0)
declare -a my_array_f3=(0 1 1 0 0 0 0 1 1 1 1 1)
declare -a my_array_f4=(1 0 0 1 0 0 0 1 0 0 0 0)
declare -a my_array_f5=(0 0 0 1 0 0 0 0 0 0 0 0)
declare -a my_array_f6=(0 1 1 0 0 0 0 0 0 0 0 0)
declare -a my_array_f7=(0 0 1 1 0 0 0 0 0 1 0 0)
declare -a my_array_f8=(1 0 0 1 0 0 0 0 0 1 0 0)
declare -a js_array_map1=('JS1' 'JS2' 'JS3' 'JS4' 'JS5' 'JS6' 'JX1-225' 'JX1-224' 'JS7' 'JS8' 'JS9' 'JS10')
declare -a js_array_map2=('JS11' 'JS12' 'JS13' 'JS14' 'JS15' 'JS16' 'JX2-225' 'JX2-224' 'JS17' 'JS18' 'JS19' 'JS20')
if [ $param_n != 0 ]
then
#let sc+=1
#sc = `expr $sc + 1`
#sc=$((${sc} + 1))
a=$1
c=$1
fpga_addr0=$((${fpga_addr0} + 0x00400000*$((${a} - 1))))
fpga_addr1=$((${fpga_addr1} + 0x00400000*$((${a} - 1))))
# for ((i=0;i<=11;i++)) do
# my_array_f[$i]=${my_array_f3[$i]}
# done
case ${a} in
[1])
#my_array_f=${my_array_f1[*]}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f1[$i]}
done
;;
[2])
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f2[$i]}
done
#my_array_f=${my_array_f2[*]}
;;
[3])
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f3[$i]}
done
;;
[4])
#my_array_f=${my_array_f4}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f4[$i]}
done
;;
[5])
#my_array_f=${my_array_f5}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f5[$i]}
done
;;
[6])
#my_array_f=${my_array_f6}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f6[$i]}
done
;;
[7])
# my_array_f=${my_array_f7}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f7[$i]}
done
;;
[8])
# my_array_f=${my_array_f8}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f8[$i]}
done
;;
*)
echo "error"
esac
#echo $sc
else
echo "no input param:read F1->F8"
#echo $fc
fi
echo "--------------------------------------"
for I in `seq $a $c`;do
echo "f$I:GT_POS"
#echo "f$I:${fpga_addr0} ${fpga_addr1}"
printf '%#x\t%#x\n' ${fpga_addr0} ${fpga_addr1}
echo "------------------------------------"
last_digit=`echo ${I} | sed 's/\(.*\)\(.\)$/\2/'`
case $last_digit in
0|2|4|6|8)
for ((ii=0;ii<=11;ii++)) do
js_array_map[$ii]=${js_array_map2[$ii]}
done
js_num=10;;
#echo "This is an even number." ;;
*)
for ((ii=0;ii<=11;ii++)) do
js_array_map[$ii]=${js_array_map1[$ii]}
done
js_num=0;;
#echo "This is not an even number." ;;
esac
for J in `seq 0 11`;do #J---FPGA number
gtpos_addr0=$((0x00000900 + 0x00000004*$((${J}))))
if [ ${my_array_f[$J]} -eq 1 ]
then
sleep 0
./devmem.sh ${fpga_addr0} 32 ${gtpos_addr0}
sleep 0
./devmem.sh ${fpga_addr1} > /dev/null
sleep 0
res=`./devmem.sh ${fpga_addr1}`
echo ${res}
#echo ${res:9:1}
from_js_pos_num=${res:11:1}
#echo "$from_js_pos_num"
if [ ${res:11:1} == 'a' ]
then
from_js_pos_num=10
fi
if [ ${res:11:1} == 'b' ]
then
from_js_pos_num=11
fi
if [ ${res:11:1} == 'c' ]
then
from_js_pos_num=12
fi
tofpga_num=${res:9:1}
last_tofpga_num=`echo ${tofpga_num} | sed 's/\(.*\)\(.\)$/\2/'`
case $last_tofpga_num in
0|2|4|6|8)
echo "From FPGA: ${res:9:1} , GT: ${js_array_map2[$((12-$from_js_pos_num))]} , to FPGA: $I, GT: ${js_array_map[$((11-$J))]}"
js_num=10;;
#echo "This is an even number." ;;
*)
echo "From FPGA: ${res:9:1} , GT: ${js_array_map1[$((12-$from_js_pos_num))]} , to FPGA: $I, GT: ${js_array_map[$((11-$J))]}"
js_num=0;;
#echo "This is not an even number." ;;
esac
#echo ${res:11:1}
#echo "${js_array_map[$((11-$J))]}"
fi
done
fpga_addr0=$((${fpga_addr0} + 0x00400000))
fpga_addr1=$((${fpga_addr1} + 0x00400000))
a=$((${a} + 1))
#
case ${a} in
[1])
#my_array_f=${my_array_f1[*]}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f1[$i]}
done
;;
[2])
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f2[$i]}
done
#my_array_f=${my_array_f2[*]}
;;
[3])
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f3[$i]}
done
;;
[4])
#my_array_f=${my_array_f4}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f4[$i]}
done
;;
[5])
#my_array_f=${my_array_f5}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f5[$i]}
done
;;
[6])
#my_array_f=${my_array_f6}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f6[$i]}
done
;;
[7])
# my_array_f=${my_array_f7}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f7[$i]}
done
;;
[8])
# my_array_f=${my_array_f8}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f8[$i]}
done
;;
*)
esac
done
第二版/改进版:
#!/bin/bash
#declare -i c=$1
echo "Start Read_GT_POS ..."
a=1
#c=8
c=4
fpga_addr0=0xc0400000
fpga_addr1=0xc0400008
param_n=$#
echo input_number:${param_n}
echo "note:param1:1~8 represent F1~F8"
declare -a my_array_f=(0 0 0 0 0 0 0 0 0 0 0 0)
declare -a my_array_f_o=(0 0 0 0 0 0 0 0 0 0 0 0)
#declare -a my_array_f1=(0 0 0 0 0 0 0 0 0 0 0 0)
#declare -a my_array_f2=(1 1 1 0 0 0 0 0 0 0 0 0)
#declare -a my_array_f3=(0 1 1 0 0 0 0 1 1 1 1 1)
#declare -a my_array_f4=(1 0 0 1 0 0 0 1 0 0 0 0)
#declare -a my_array_f5=(0 0 0 1 0 0 0 0 0 0 0 0)
#declare -a my_array_f6=(0 1 1 0 0 0 0 0 0 0 0 0)
#declare -a my_array_f7=(0 0 1 1 0 0 0 0 0 1 0 0)
#declare -a my_array_f8=(1 0 0 1 0 0 0 0 0 1 0 0)
#declare -a js_array_map1=('JS1' 'JS2' 'JS3' 'JS4' 'JS5' 'JS6' 'JX1-225' 'JX1-224' 'JS7' 'JS8' 'JS9' 'JS10')
#declare -a js_array_map2=('JS11' 'JS12' 'JS13' 'JS14' 'JS15' 'JS16' 'JX2-225' 'JX2-224' 'JS17' 'JS18' 'JS19' 'JS20')
#vuls quad 440 for hcd
#declare -a my_array_f1=(1 0 0 0 0 0 1 1 0 1 1 1)
#declare -a my_array_f2=(1 1 1 0 1 1 0 0 0 0 1 1)
#declare -a my_array_f3=(1 1 1 0 0 0 0 0 0 0 1 1)
#declare -a my_array_f4=(1 1 0 0 1 1 0 0 0 0 1 1)
#declare -a my_array_f5=(0 0 0 1 0 0 0 0 0 0 0 0)
#declare -a my_array_f6=(0 1 1 0 0 0 0 0 0 0 0 0)
#declare -a my_array_f7=(0 0 1 1 0 0 0 0 0 1 0 0)
#declare -a my_array_f8=(1 0 0 1 0 0 0 0 0 1 0 0)
declare -a my_array_f1=(1 1 1 1 1 1 1 1 1 1 1 1)
declare -a my_array_f2=(1 1 1 1 1 1 1 1 1 1 1 1)
declare -a my_array_f3=(1 1 1 1 1 1 1 1 1 1 1 1)
declare -a my_array_f4=(1 1 1 1 1 1 1 1 1 1 1 1)
declare -a my_array_f5=(0 0 0 1 0 0 0 0 0 0 0 0)
declare -a my_array_f6=(0 1 1 0 0 0 0 0 0 0 0 0)
declare -a my_array_f7=(0 0 1 1 0 0 0 0 0 1 0 0)
declare -a my_array_f8=(1 0 0 1 0 0 0 0 0 1 0 0)
declare -a my_array_f1_o=(1 1 1 1 1 1 1 1 1 1 1 1)
declare -a my_array_f2_o=(1 1 1 1 1 1 1 1 1 1 1 1)
declare -a my_array_f3_o=(1 1 1 1 1 1 1 1 1 1 1 1)
declare -a my_array_f4_o=(1 1 1 1 1 1 1 1 1 1 1 1)
declare -a my_array_f5_o=(0 0 0 1 0 0 0 0 0 0 0 0)
declare -a my_array_f6_o=(0 1 1 0 0 0 0 0 0 0 0 0)
declare -a my_array_f7_o=(0 0 1 1 0 0 0 0 0 1 0 0)
declare -a my_array_f8_o=(1 0 0 1 0 0 0 0 0 1 0 0)
#vu ls quad ls
declare -a js_array_map1=('J4' 'J3' 'J2' 'J1+J8' 'JX2-M1' 'JX2-M2' 'JX1-M1' 'JX1-M2' 'MDM' 'J7' 'J6' 'J5')
declare -a js_array_map2=('J4' 'J3' 'J2' 'J1+J8' 'JX2-M1' 'JX2-M2' 'JX1-M1' 'JX1-M2' 'MDM' 'J7' 'J6' 'J5')
if [ $param_n != 0 ]
then
#let sc+=1
#sc = `expr $sc + 1`
#sc=$((${sc} + 1))
a=$1
c=$1
fpga_addr0=$((${fpga_addr0} + 0x00400000*$((${a} - 1))))
fpga_addr1=$((${fpga_addr1} + 0x00400000*$((${a} - 1))))
#
# for ((i=0;i<=11;i++)) do
# my_array_f[$i]=${my_array_f3[$i]}
# done
case ${a} in
[1])
#my_array_f=${my_array_f1[*]}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f1[$i]}
done
;;
[2])
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f2[$i]}
done
#my_array_f=${my_array_f2[*]}
;;
[3])
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f3[$i]}
done
;;
[4])
#my_array_f=${my_array_f4}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f4[$i]}
done
;;
[5])
#my_array_f=${my_array_f5}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f5[$i]}
done
;;
[6])
#my_array_f=${my_array_f6}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f6[$i]}
done
;;
[7])
# my_array_f=${my_array_f7}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f7[$i]}
done
;;
[8])
# my_array_f=${my_array_f8}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f8[$i]}
done
;;
*)
echo "error"
esac
#echo $sc
else
echo "no input param:read F1->F8"
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f1[$i]}
done
#echo $fc
fi
echo "--------------------------------------"
for I in `seq $a $c`;do
echo "f$I:GT_POS"
#echo "f$I:${fpga_addr0} ${fpga_addr1}"
#printf '%#x\t%#x\n' ${fpga_addr0} ${fpga_addr1}
#echo "------------------------------------"
last_digit=`echo ${I} | sed 's/\(.*\)\(.\)$/\2/'`
case $last_digit in
0|2|4|6|8)
for ((ii=0;ii<=11;ii++)) do
js_array_map[$ii]=${js_array_map2[$ii]}
done
js_num=10;;
#echo "This is an even number." ;;
*)
for ((ii=0;ii<=11;ii++)) do
js_array_map[$ii]=${js_array_map1[$ii]}
done
js_num=0;;
#echo "This is not an even number." ;;
esac
for J in `seq 0 11`;do #J---FPGA number
gtpos_addr0=$((0x00000900 + 0x00000004*$((${J}))))
if [ ${my_array_f[$J]} -eq 1 ]
then
#sleep 0
./devmem.sh ${fpga_addr0} 32 ${gtpos_addr0}
#sleep 0
./devmem.sh ${fpga_addr1} > /dev/null
#sleep 0
#20210306
#lane1
res_lane1=`./devmem.sh ${fpga_addr1}`
#lane2-4
gtpos_addr_temp=${gtpos_addr0}
let gtpos_addr_temp++
./devmem.sh ${fpga_addr0} 32 ${gtpos_addr_temp}
./devmem.sh ${fpga_addr1} > /dev/null
res_lane2=`./devmem.sh ${fpga_addr1}`
let gtpos_addr_temp++
./devmem.sh ${fpga_addr0} 32 ${gtpos_addr_temp}
./devmem.sh ${fpga_addr1} > /dev/null
res_lane3=`./devmem.sh ${fpga_addr1}`
let gtpos_addr_temp++
./devmem.sh ${fpga_addr0} 32 ${gtpos_addr_temp}
./devmem.sh ${fpga_addr1} > /dev/null
res_lane4=`./devmem.sh ${fpga_addr1}`
res="0x0001:0xFFFF"
if [[ `echo ${res_lane4} | grep 'FFFF' ` == '' ]] ;then
res=${res_lane4}
fi
if [[ `echo ${res_lane3} | grep 'FFFF' ` == '' ]] ;then
res=${res_lane3}
fi
if [[ `echo ${res_lane2} | grep 'FFFF' ` == '' ]] ;then
res=${res_lane2}
fi
if [[ `echo ${res_lane1} | grep 'FFFF' ` == '' ]] ;then
res=${res_lane1}
fi
echo "lane1-4:${res_lane1}_${res_lane2}_${res_lane3}_${res_lane4}"
#0x0001:0x08AC 0x0001:0xFFFF 0x0001:0xFFFF 0x0001:0xFFFF 0x0001:0xFFFF 0x0001:0xFFFF 0x0001:0x07A3 0x0001:0x07A2 0x0001:0xFFFF 0x0001:0x06A3 0x0001:0x06A2 0x0001:0x08A1
#echo ${res}
#echo ${res:9:1}
res_t=`echo ${res} | grep 'FFFF' `
if [[ ${res_t} == '' ]] ;then
res_t=`echo ${res} | grep 'ffff' `
fi
if [[ ${res_t} != '' ]] ; then
my_array_f_o[$J]=0;
else
my_array_f_o[$J]=1;
from_js_pos_num=${res:12:1}
#echo "$from_js_pos_num"
if [[ ${res:12:1} == 'a' || ${res:12:1} == 'A' ]]
then
from_js_pos_num=10
fi
if [[ ${res:12:1} == 'b' || ${res:12:1} == 'B' ]]
then
from_js_pos_num=11
fi
if [[ ${res:12:1} == 'c' || ${res:12:1} == 'C' ]]
then
from_js_pos_num=12
fi
#echo "$from_js_pos_num"
tofpga_num=${res:10:1}
last_tofpga_num=`echo ${tofpga_num} | sed 's/\(.*\)\(.\)$/\2/'`
case $last_tofpga_num in
0|2|4|6|8)
echo "From FPGA: ${res:10:1} , GT: ${js_array_map2[$((12-$from_js_pos_num))]} , to FPGA: $I, GT: ${js_array_map[$((11-$J))]}"
js_num=10;;
#echo "This is an even number." ;;
*)
echo "From FPGA: ${res:10:1} , GT: ${js_array_map1[$((12-$from_js_pos_num))]} , to FPGA: $I, GT: ${js_array_map[$((11-$J))]}"
js_num=0;;
#echo "This is not an even number." ;;
esac
#echo ${res:11:1}
#echo "${js_array_map[$((11-$J))]}"
fi
fi
done
#
#
fpga_addr0=$((${fpga_addr0} + 0x00400000))
fpga_addr1=$((${fpga_addr1} + 0x00400000))
a=$((${a} + 1))
#
case ${a} in
[1])
#my_array_f=${my_array_f1[*]}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f1[$i]}
done
;;
[2])
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f2[$i]}
done
#my_array_f=${my_array_f2[*]}
for ((ii=0;ii<=11;ii++)) do
my_array_f1_o[$ii]=${my_array_f_o[$ii]}
done
;;
[3])
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f3[$i]}
done
for ((ii=0;ii<=11;ii++)) do
my_array_f2_o[$ii]=${my_array_f_o[$ii]}
done
;;
[4])
#my_array_f=${my_array_f4}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f4[$i]}
done
for ((ii=0;ii<=11;ii++)) do
my_array_f3_o[$ii]=${my_array_f_o[$ii]}
done
;;
[5])
#my_array_f=${my_array_f5}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f5[$i]}
done
for ((ii=0;ii<=11;ii++)) do
my_array_f4_o[$ii]=${my_array_f_o[$ii]}
done
;;
[6])
#my_array_f=${my_array_f6}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f6[$i]}
done
for ((ii=0;ii<=11;ii++)) do
my_array_f5_o[$ii]=${my_array_f_o[$ii]}
done
;;
[7])
# my_array_f=${my_array_f7}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f7[$i]}
done
for ((ii=0;ii<=11;ii++)) do
my_array_f6_o[$ii]=${my_array_f_o[$ii]}
done
;;
[8])
# my_array_f=${my_array_f8}
for ((i=0;i<=11;i++)) do
my_array_f[$i]=${my_array_f8[$i]}
done
for ((ii=0;ii<=11;ii++)) do
my_array_f7_o[$ii]=${my_array_f_o[$ii]}
done
;;
[9])
for ((ii=0;ii<=11;ii++)) do
my_array_f8_o[$ii]=${my_array_f_o[$ii]}
done
;;
*)
esac
done
#display link out:
#declare -a my_array_f1=(1 0 0 0 0 0 1 1 0 1 1 1)
#declare -a my_array_f2=(1 1 1 0 1 1 0 0 0 0 1 1)
#declare -a my_array_f3=(1 1 1 0 0 0 0 0 0 0 1 1)
#declare -a my_array_f4=(1 1 0 0 1 1 0 0 0 0 0 0)
#declare -a my_array_f5=(0 0 0 1 0 0 0 0 0 0 0 0)
#declare -a my_array_f6=(0 1 1 0 0 0 0 0 0 0 0 0)
#declare -a my_array_f7=(0 0 1 1 0 0 0 0 0 1 0 0)
#declare -a my_array_f8=(1 0 0 1 0 0 0 0 0 1 0 0)
echo "----------------------"
echo "f1:${my_array_f1_o[*]}"
echo "f2:${my_array_f2_o[*]}"
echo "f3:${my_array_f3_o[*]}"
echo "f4:${my_array_f4_o[*]}"
echo "" > ./gt_linkmap.sh
echo "#!/bin/bash" >> ./gt_linkmap.sh
echo "declare -a my_array_f1=(${my_array_f1_o[*]})" >> ./gt_linkmap.sh
echo "declare -a my_array_f2=(${my_array_f2_o[*]})" >> ./gt_linkmap.sh
echo "declare -a my_array_f3=(${my_array_f3_o[*]})" >> ./gt_linkmap.sh
echo "declare -a my_array_f4=(${my_array_f4_o[*]})" >> ./gt_linkmap.sh
echo "" >> ./gt_linkmap.sh