Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If the arguments are to be evaluated locally, by bash, then the wild cards and brace expansion shouldn't be in quotes.
If you precede a connand with set, you can examine the arguments $1, $2, etc. to verify what arguments the command sees after bash performs the various expansions.
change
Code:
SOURCE="{argomentare,bibliografie,documenti}"
in
SOURCE={argomentare,bibliografie,documenti}
samiel@debian:~$ bash -x backup.sh
+ SOURCE='{argomentare,bibliografie,documenti}'
+ TARGET=/media/CORSAIR
++ date +%y-%M-%D
+ date=12-35-08/12/12
+ TAG=backup
+ mount
+ grep -q /media/CORSAIR
+ echo 'Il disco è montato: eseguo il backup'
Il disco è montato: eseguo il backup
++ hostname
+ logger Inizio backup di '{argomentare,bibliografie,documenti}' per debian -t backup
+ rsync -rvu --progress '{argomentare,bibliografie,documenti}' /media/CORSAIR
sending incremental file list
rsync: link_stat "/home/samiel/{argomentare,bibliografie,documenti}" failed: No such file or directory (2)
sent 12 bytes received 12 bytes 48.00 bytes/sec
total size is 0 speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1070) [sender=3.0.9]
++ hostname
+ logger Fine backup per debian: rsync ha restituito -t backup
+ exit 0
Ok ... so now I think I am following a little better (sorry it took a while).
So on the command line you use brace expansion to list your multiple directories in the current path. So my suggestion still holds that an array would probably suit.
I do however still think the earlier suggestion of an include or exclude file would make this simpler.
Now working !!
Only a last proble. For I've a lot of directories,
I must split comman on more lines. In the script,
the backslash doesn't seem to work:
samiel@debian:~$ bash -x backup.sh
+ SOURCE=(argomentare,bibliografie,cataloghi,condominio,copertine,cratilo, dialettica,dizionario,documenti,elisp,ermeneutica,esperienza,ezine,fichte, filosofi,guide_debian,guide_latex,guide_linux,guide_php,guide_slackware, html4dummies,mail,manuale,mutt4dummies,neopositivisti,noneuclidee,novecento, protagonisti,protagonisti_nuovo,public_html,retorica,s4d_project,sabina, sacchettino,Scaricati,schelling,scuola,slack4dummies,slackbook,songs,storia, tesi,texmf, tin4dummies,tractatus,xindy)
+ TARGET=/media/CORSAIR
+ rsync -rvu --progress argomentare,bibliografie,cataloghi,condominio,copertine,cratilo, dialettica,dizionario,documenti,elisp,ermeneutica,esperienza,ezine,fichte, filosofi,guide_debian,guide_latex,guide_linux,guide_php,guide_slackware, html4dummies,mail,manuale,mutt4dummies,neopositivisti,noneuclidee,novecento, protagonisti,protagonisti_nuovo,public_html,retorica,s4d_project,sabina, sacchettino,Scaricati,schelling,scuola,slack4dummies,slackbook,songs,storia, tesi,texmf, tin4dummies,tractatus,xindy /media/CORSAIR
sending incremental file list
rsync: link_stat "/home/samiel/argomentare,bibliografie,cataloghi,condominio,copertine,cratilo," failed: No such file or directory (2)
rsync: link_stat "/home/samiel/dialettica,dizionario,documenti,elisp,ermeneutica,esperienza,ezine,fichte," failed: No such file or directory (2)
rsync: link_stat "/home/samiel/filosofi,guide_debian,guide_latex,guide_linux,guide_php,guide_slackware," failed: No such file or directory (2)
rsync: link_stat "/home/samiel/html4dummies,mail,manuale,mutt4dummies,neopositivisti,noneuclidee,novecento," failed: No such file or directory (2)
rsync: link_stat "/home/samiel/protagonisti,protagonisti_nuovo,public_html,retorica,s4d_project,sabina," failed: No such file or directory (2)
rsync: link_stat "/home/samiel/sacchettino,Scaricati,schelling,scuola,slack4dummies,slackbook,songs,storia," failed: No such file or directory (2)
rsync: link_stat "/home/samiel/tesi,texmf," failed: No such file or directory (2)
rsync: link_stat "/home/samiel/tin4dummies,tractatus,xindy" failed: No such file or directory (2)
sent 12 bytes received 12 bytes 48.00 bytes/sec
total size is 0 speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1070) [sender=3.0.9]
samiel@debian:~$ bash -x backup.sh
+ SOURCE=(argomentare,bibliografie,cataloghi)
+ TARGET=/media/CORSAIR
+ rsync -rvu --progress argomentare,bibliografie,cataloghi /media/CORSAIR
sending incremental file list
rsync: link_stat "/home/samiel/argomentare,bibliografie,cataloghi" failed: No such file or directory (2)
sent 12 bytes received 12 bytes 48.00 bytes/sec
total size is 0 speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1070) [sender=3.0.9]
I did not notice previously, but you have placed commas in the array and hence rendered it not an array but a single string. Now that you have the new lines
being interpreted as white space it breaks the array into pieces based on the new line. The commas were required when you used {} as this indicates how to expand the
braces in the shell, ie where a word ends, but an array uses white space.
Try replacing all commas with a space. Obviously if any of your file / directory names have a space in them this will cause issues. Again why I would recommend the include file.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.