You're hammering nails with a wrench. I'm not teasing. This is how we learn. But give this a try:
Make a file in /root called "backup.txt" or some such, instead of hard coding an array.
Code:
touch /root/backup.txt
nano /root/backup.txt
enter the paths of all your "include" files/directories, there
Then, as was mentioned, use a FOR..IN to pack them into the command.
Code:
#!/bin/bash
for I in `cat /root/backup.txt`
do
cp -a $I /$DEST
#Or substitute with your command of choice
done
This is better because it's WAY easier to update a text file than a hard coded array. It also shows a good bit about how UNIX works. Extracting info from a text file is called parsing and it's one of the biggest jobs for an old school admin. It gives you a lot of power to control your system.
In this vein we could go a little deeper and write an awk script to parse the data
Code:
/#.*/ {
# Ignore any comments
next
}
/^$/ {
#ignore blank lines
next
}
/.*/ {
#Act on anything else
system("cp -a $1 /HARD_CODED_PATH")
next
}
the script above will allow you to write comments (#) and skip lines in the backup.txt file. Nice for leaving yourself notes. Save it as backup.awk.
call it like this:
Code:
awk -f backup.awk backup.txt
Just a few options
HMW was absolutely right about how to code an array. You're much better off with a config file, though.
Finally. This is great training, but if backup is your desire, please check out rsync (man rsync). It's a backup dream come true and very worth learning.
cheers