Bash 向变量附加额外的字符?

Bash appending extra characters to variable?

我正在尝试将值存储在变量中并将结果回显到文件中。但是当它添加两个变量并将其回显到一个文件时,额外的字符被添加到输出文件中。这发生在 docker 容器中,有人可以帮忙吗...

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    

我无法重现问题,但您的代码比需要的更复杂。

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