我试图将值存储在变量中并尝试将结果回显到文件中。但是当它添加两个变量并将其回显到文件时,会在输出文件中添加额外的字符。这发生在码头工人的容器中,有人可以帮忙......
IFS=" "
#while read line
while read c s e
do
echo $c $s $e
first=$(echo "PER_${s}_${e}")
#echo -n $first
second=$(echo "/IPD_${c}")
#echo $second
echo $first$second >> /mnt/resource/step2/messages.txt
done < /mnt/resource/step2/job_control/Categories.txt
Categories.txt包含:
129490 201515 201540
我得到的输出为:
PER__/IPD_PER_201515_201540/IPD_12949029490
但它应该是这样的:
PER_201515_201540/IPD_129490
答案 0 :(得分:1)
我无法重现问题,但您的代码比实际需要的更复杂。
while IFS=" " read c s e; do
first="PER_${s}_${e}"
second="/IPD_${c}"
echo "$first$second" >> /mnt/resource/step2/messages.txt
done < /mnt/resource/step2/job_control/Categories.txt