Bash: how to distribute an array into lines in a script
Hi all,
well, the subjet isn't very meaningfull, is it ;-) I'm writing a backup-script and want to have a separate configuration script. As yet my Script has the following lines: Code:
... Code:
FILES="/root /etc /home/$BACKUPUSER /usr/local /var/spool/cron/crontabs" Code:
myarray=($FILES) Code:
--include $1 \ Thanks in advance Markus |
This seems overly complicated, but I might be missing the point somewhere. Can't you just loop the array?
Code:
$ echo "${myarr[@]}" Code:
$ for item in "${myarr[@]}"; do echo "--include $item \\"; done Best regards, HMW |
hmmm ... I think part of the problem here is you have not really provided enough information about what backup program you are using (something like rsync??).
So my first question back would be, can your backup program that uses --include switch not accept multiple paths for a single switch? If you are going define as an array, I would just do it straight off instead of first placing it in a space separated string. Lastly, you can also use HMW's method to build your command line and then execute that. |
Quote:
Markus |
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 Then, as was mentioned, use a FOR..IN to pack them into the command. Code:
#!/bin/bash In this vein we could go a little deeper and write an awk script to parse the data Code:
/#.*/ { call it like this: Code:
awk -f backup.awk backup.txt 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 |
All times are GMT -5. The time now is 08:00 AM. |