demo参考如下:
aa=(hello world I am chinese)
arr=()
for i in ${aa[@]}
do
#echo "i= $i"
arr[${#arr[@]}]=$i
echo "+ $i "
done
echo "print the array result: "
echo "shell format output"
for val in ${arr[@]}
do
echo -e "$val \c"
done
echo ""
echo "Note the ' single quotation mark"
for((i=0;i<${#arr[@]};i++))
do
# shell 双""里面再加单引号',单引号显示为标点符号
echo -e "{$i:'${arr[i]}'} \c" >> a.txt
done
echo ""
echo "Construct dict and add to the file b.txt"
for((i=0;i<${#arr[@]};i++))
do
python3 << EOF
import json
with open('/home/hddl/dcx123/b.txt', 'a') as f:
f.write((json.dumps({$i:'${arr[i]}'})+'@@'))
EOF
done
echo ""