I'm having trouble understanding the exclude option in tar. From some web sites, it seems one is able to exclude several strings by enclosing them in curly brackets. However it seems to be "random" what gets excluded when using the curlies.
I've been using the exclude-from=myfile option in a script but would like to inline myfile into a variable and use $exclude={this,that,the_other} with the --exclude=$exclude option to keep the script self-contained.
Simple examples to illustrate:
Say I have directories C and D and want to make them into a tar file.
tar -cvf mytar.tar C D
This works.
Now for the sake of argument, I want to exclude C.
tar -cvf mytar.tar C D --exclude=C
This works as expected (C is excluded).
Now I bring in the curlies...
tar -cvf mytar.tar C D --exclude={C}
This does not exclude C, which is not what I expected.
If I try to exclude a subdirectory of C, it also doesn't work.
tar -cvf mytar.tar C D --exclude={C/subdir}
Nothing is excluded.
If I exclude both C and D, then it does work (both are excluded).
tar -cvf mytar.tar C D --exclude={C,D}
Any idea how I can get the same functionality as --exclude-from with --exclude?