Skip to main content
INcluding also the issue of $(cat file) and providing an alternative script.
Source Link
user232326
user232326

Quoting !!. The quoting on this line is missing:

mv output/input.tmp output/$name.xml

It should be:

mv output/input.tmp output/"$name".xml

to avoid issues with a file name with spaces.

And, the expansion of $(cat list) is being split (and glob) by the shell, that also breaks in spaces.

Maybe you can change to this script:

#!/bin/bash -x
rm -f output/*

inputfile=output/input.tmp

while read -r line
do
    id=${line%%;*}
    name=${line##*;}
    
    cp sample.xml "$inputfile"
    sed -i -e "s/xxx/$id/g" "$inputfile"
    sed -i -e "s/yyy/$name/g" "$inputfile"
    mv "$inputfile"  output/"$name".xml; echo
    
done <list

Quoting !!. The quoting on this line is missing:

mv output/input.tmp output/$name.xml

It should be:

mv output/input.tmp output/"$name".xml

to avoid issues with a file name with spaces.

Quoting !!. The quoting on this line is missing:

mv output/input.tmp output/$name.xml

It should be:

mv output/input.tmp output/"$name".xml

to avoid issues with a file name with spaces.

And, the expansion of $(cat list) is being split (and glob) by the shell, that also breaks in spaces.

Maybe you can change to this script:

#!/bin/bash -x
rm -f output/*

inputfile=output/input.tmp

while read -r line
do
    id=${line%%;*}
    name=${line##*;}
    
    cp sample.xml "$inputfile"
    sed -i -e "s/xxx/$id/g" "$inputfile"
    sed -i -e "s/yyy/$name/g" "$inputfile"
    mv "$inputfile"  output/"$name".xml; echo
    
done <list
Source Link
user232326
user232326

Quoting !!. The quoting on this line is missing:

mv output/input.tmp output/$name.xml

It should be:

mv output/input.tmp output/"$name".xml

to avoid issues with a file name with spaces.