# data records are separated by newline symbol,filds are separated by comma symbol
# take it as a entire string
# put it into a array
arr=(`echo -e "name=joe,id=5\nname=jack,id=7\nname=ben,id=10"`)
echo "records contents: ${arr[@]}"
echo "records number: ${#arr[@]}"
for i in ${arr[@]}
do
i=`echo "$i" | sed 's/,/ /g'`
eval "$i"
echo "name=\"$name\" id=\"$id\""
done
大概思路是这样的:
1. 把数据导出来放到一个串里,记录之间用换行符隔开
2. 然后再放到一个数组里(数组里的分隔符是空格、TAB、换行,所以记录内的字符可能得做些相关处理)
3. 逐一取出记录,并通过eval来执行记录内字段的赋值操作(eval 以空格和TAB为分隔符),再做处理
阅读(1723) | 评论(0) | 转发(0) |