It kind-of-works. However, all files (including those I nick-named ‘argh’ here), will also be copied. That’s huge binary files I don’t want to have!
Small aberrations, such as using {…} or .argh did not work. Even the seemingly straight-forward “–exclude .git --exclude *.argh” failed. I’m a bit puzzled by now.
Does anyone of you see the (probably stupid) mistake I made here?
To begin with, this is not a script at all, it is only some statmenets. A sxript should start with the so called “shebang” as first line
#!/usr/bin/bash
To skip some (a lot of) steps that are less important here:
Your rsync statement is first split by the shell into “words”. That is done on, amongst more, white space. Then variable expansipn is done, which will replace e.g. the word
${options}
with the string
-razP --exclude={'*.git*','*.argh'} --delete
. That new “word” is NOT split again. It will become ONE argument to the rsync command when it is executed on request of the shell. And the argument
-razP --exclude={'*.git*','*.argh'} --delete
will not be understood by rsync in the way you intended.
I have not tested this, but it may be that using eval will help you:
Hi
Just an FYI from a packaging experience, ‘env’ is not used and stripped from any scripts, the shell is an explicit declaration… #!/usr/bin/bash if it’s not working then maybe your $PATH has an issue.
You do not show your script so we have no way to comment on it.
eval + using --exclude ‘a’ – exclude ‘b’ … worked, but is not very elegant to use
In what way exactly? Your “elegant” solution is
less flexible as it is impossible to programmatically build exclude list incrementally
more error prone as now you have to take extra care to quote every possible unwanted shell expansion
more slow as it adds extra unneeded processing
Having some construct in a language does not mean it must be used by all means. Brace expansion was designed for interactive use to reduce amount of typing. Scripts must be robust and easy to understand unless you attempt to win obfuscated programming contest or prepare your home work.
in combination with the exchange of " " ↔ ’ ', it seems to work
When you transition to a much longer list of exclusions, you might be better off with the more flexible --filter parameter that keeps your command line a bit more readable:
The double bracket, which is a shell keyword, enables additional functionality. For example, you can use && and || instead of -a and -o and there’s a regular expression matching operator =~.
Also, in a simple test, double square brackets seem to evaluate quite a lot quicker than single ones.
$ time for ((i=0; i<10000000; i++)); do “$i” = 1000 ]]; done
real 0m24.548s
user 0m24.337s
sys 0m0.036s
$ time for ((i=0; i<10000000; i++)); do “$i” = 1000 ]; done