把awk中的数组赋值给shell中的数组
方法1,通过eval
#!/bin/bash ipstr="192.168.1.152,192.168.1.153"; #declare -a arr; eval $(echo $ipstr | awk '{split($0, filearray, ",");for(i in filearray)print "arr["i"]="filearray[i]}') #eval 把print的内容,和javascript的eval一样的功能 #echo ${arr[1]} for i in ${arr[*]} do #scp_c="scp $i:/opt/flow_video/2011-05-26.txt" #echo $scp_c scp $i:/opt/flow_video/2011-05-26.txt /opt/flow_video/2011-05-26_$i.txt done
方法2通过临时文件
#!/bin/sh count=0 str="123#abc#@&?" `awk 'BEGIN { split("'"$str"'",a,"#")} END { for (i in a) {print a[i];$count++; }}' /dev/null > 2` while read buf do tArray[$c]=$buf c=$(expr $c + 1) done < 2 echo "array len:" $c for((i=0;i<$c;i++)); do echo ${tArray[$i]} done
执行输出
arraylen:3
123
abc
@&?
相关推荐
fendou00sd 2020-06-16
chenpro 2020-07-04
RealJianyuan 2020-06-14
cwgxiaoguizi 2020-06-05
chenpro 2020-06-02
Neptune 2020-05-31
老谢的自留地 2020-05-09
YukiRain 2020-05-08
baobaozai 2020-04-29
Proudoffaith 2020-04-08
fenxinzi 2020-03-01
zhiliang 2020-01-31
wannagonna 2020-01-13
wandererdl 2019-12-25
chenchuang 2020-01-25
jyj00 2020-01-09
fendou00sd 2020-01-07
fendou00sd 2020-01-06
PHP学习笔记 2020-01-06