awkの配列をshellの配列に割り当てます.
1003 ワード
方法1,evalを通じて
array len:3
123
abc
@&
#!/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;ido
echo ${tArray[$i]}
done
出力を実行array len:3
123
abc
@&