Backup files from different directories with the same name problem

Hi, I have tried multiple ways to solve this with no success, unfortunately.

I have a variable like this:
echo $var
/etc/tomcat/server.xml /etc/tomcat/test/server.xml

How can I backup both files from this variable with different names? I tried setting it as an array var2=($var) but it only shows the first file.

Thanks in advance for te help.

This is working as expected in bash 4.4.12

$ var="/etc/tomcat/server.xml /etc/tomcat/test/server.xml"
$ var2=( $var )
$ echo ${var2[0]}
/etc/tomcat/server.xml
$ echo ${var2[1]}
/etc/tomcat/test/server.xml
$ echo $BASH_VERSION
4.4.12(3)-release
1 Like

I found an alternative solution where tar is used. And it backs up all files with the same name along in their unique directory names.

find /dirname -name server.xml -exec tar -rvf /opt/server.xml-backup.tar-$(date +%F) '{}' \;