I have the following directory structure which I want to zip:
dir2zip
subdir1
file1.txt
subdir2
file2.txt
subdir3
file3.txt
I want to exclude subdir3
, so I use the following command line:
zip -r dir2zip.zip dir2zip -x "dir2zip/subdir3/*"
When performing this on the prompt, the following correct output is received:
manfred@altair:~/data$ zip -r dir2zip.zip dir2zip -x "dir2zip/subdir3/*"
adding: dir2zip/ (stored 0%)
adding: dir2zip/subdir2/ (stored 0%)
adding: dir2zip/subdir2/file2.txt (deflated 72%)
adding: dir2zip/subdir1/ (stored 0%)
adding: dir2zip/subdir1/file1.txt (deflated 68%)
But when I'm doing this in a script where the arguments are composed to a string, e.g. like this:
manfred@altair:~/data$ zipvar="-r dir2zip.zip dir2zip -x \"dir2zip/subdir3/*\""
manfred@altair:~/data$ echo $zipvar
-r dir2zip.zip dir2zip -x "dir2zip/subdir3/*"
...and I execute zip with this variable as argument, then the output is like this:
manfred@altair:~/data$ zip $zipvar
adding: dir2zip/ (stored 0%)
adding: dir2zip/subdir3/ (stored 0%)
adding: dir2zip/subdir3/file3.txt (deflated 94%)
adding: dir2zip/subdir2/ (stored 0%)
adding: dir2zip/subdir2/file2.txt (deflated 72%)
adding: dir2zip/subdir1/ (stored 0%)
adding: dir2zip/subdir1/file1.txt (deflated 68%)
Here zip does also compress subdir3
, it looks like when executing zip with arguments in a variable, it ignores some of them.
Has anybody a hint how I can use zip with arguments generated by a script to a variable? I don't want to write all my zip commands explicitely in the script, the list would be much too long and too unflexible...