I've encountered with kinda strange behaviour of 7z (or bash, I don't know yet.). With the following script:

find /home/user  -type f -name "*.pdf" | cut -c 10- > /home/user/exclude_list2.lst;
lst1=" -x@/home/user/exclude_list2.lst -xr!'*.config/*' -xr!'*.cache/*' "
command=$(/usr/bin/7z a $lst1 -v2048M arch0.7z /home/user);

also, the last two lines can be easily substituted with single line:

/usr/bin/7z a $lst1 -v2048M arch0.7z /home/user

I've also tried :

command="/usr/bin/7z a  $lst1  -v2048M arch0.7z /home/dh ;"

I receive a 'arch0.7z' file, but folders .config and .cache are being included still, while:

find /home/user  -type f -name "*.pdf" | cut -c 10- > /home/user/exclude_list2.lst;
/usr/bin/7z a -x@/home/user/exclude_list2.lst -xr!'*.config/*' -xr!'*.cache/*' -v2048M arch0.7z /home/user ;"

generates a file with properly excluded folders.

So, I wonder, what is the difference between the line expanded from variable:

/usr/bin/7z a $lst1 -v2048M arch0.7z /home/user

and the one I've typed as is:

 /usr/bin/7z a -x@/home/user/exclude_list2.lst -xr!'*.config/*' -xr!'*.cache/*' -v2048M arch0.7z /home/user

Is there any reason for such significant changes in 7z workflow?

  • This appears to have a typo. The line should be something like: command=$(/usr/bin/7z a $lst1 -v2048M arch0.7z /home/user); – krowe Sep 24 '14 at 4:34
  • nope, that was just a typo. Original script has all parentheses on place. – Dmytro Kh. Sep 24 '14 at 5:27
  • 1
    right, sorry for that, mixed few lines. It seems, I've copied without errors now. – Dmytro Kh. Sep 24 '14 at 5:35

That's something I wasn't expecting for.

lst1=' -xr@/home/me/exclude_list2.lst -xr!'*.config/*' -xr!'*.cache/*' -xr!'*.local/*' '
7z a $lst1 -v2048M arch0.7z /home/me

do the trick, while I was thinking that single quote in -xr!'.config/' will end the variable assignment, it actually works as a part of argument. Also, works perfectly if my variable is an array.

By the way, escaping with "!" won't work, 7z says "Error: Incorrect command line" for it.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.