You need some sort of evaluation in order to check what to exclude from the list of folders you get in the "for"; just using bash this could be (you can use whatever you feel comfortable to evaluate what to exclude (ie sed, grep, awk,...)):
exclusiondirs="/home/foo /home/bar" # list of folders to exclude from backup
for a in /home/*; do
if ! [[ "$exclusiondirs" =~ $a ]]; then
...do backup...
fi
done
However I would have use some other tools for backup such rsync which can exclude by itself, for example:
Since the bash regex is a bit tricky and difficult to implement in some circumstances I've replaced it with a more robust grep statement:
if ! echo "$exclusiondirs" | grep -q "\b$a\b" ; then
This grep statement will work in a home dir with names such as (where some dirs share common part names and include spaces within):
mkdir -p home/{foo,bar,foobar,a,b,c,a\ b
tree
`-- home
|-- a
|-- a b
|-- b
|-- bar
|-- c
|-- foo
`-- foobar
~$ echo $exclusiondirs
/home/foo /home/bar /home/a
~$ for a in /home/*; do if ! echo "$exclusiondirs" | grep -q "\b$a\b" ; then echo $a; fi; done
/home/a b
/home/b
/home/c
/home/foobar
You need some sort of evaluation in order to check what to exclude from the list of folders you get in the "for"; just using bash this could be (you can use whatever you feel comfortable to evaluate what to exclude (ie sed, grep, awk,...)):
However I would have use some other tools for backup such rsync which can exclude by itself, for example:
Edited:
Since the bash regex is a bit tricky and difficult to implement in some circumstances I've replaced it with a more robust grep statement:
This grep statement will work in a home dir with names such as (where some dirs share common part names and include spaces within):
Go to Skipping multiple files and folders section in this page.