I've encountered with kinda strange behaviour of 7z (or bash, I don't know yet.).With the following script:#!/bin/bashfind /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);$commandalso, the last two lines can be easily substituted with single line:/usr/bin/7z a $lst1 -v2048M arch0.7z /home/userI'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:#!/bin/bashfind /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/userand 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/userIs there any reason for such significant changes in 7z workflow?
7z from bash script won't exclude directories
bash;scripting;shell script
Your original formcommand=$(/usr/bin/7z a $lst1 -v2048M arch0.7z /home/user);$commandwill mean that $command contains the output of the 7zip run, as var=$(...) will store the output of a command into the variable. Therefore, /usr/bin/7z a $lst1 -v2048M arch0.7z /home/useris a not a substitution, but a correction of the error in the script. Anyway, to the real issue. If you run the variable assignment in the shell, you will notice the following: $ lst1= -x@/home/user/exclude_list2.lst -xr!'*.config/*' -xr!'*.cache/*' -bash: !'*.config/*': event not foundSo, you have an error in this line, as the shell will do variable substitution etc. when double quotes ... are used. The problematic item is the !, as it used by bash to refer to previous commands in its history. Use single quotes instead: '...'$ lst1=' -x@/home/user/exclude_list2.lst -xr!'*.config/*' -xr!'*.cache/*' '$ echo $lst1-x@/home/user/exclude_list2.lst -xr!*.config/* -xr!*.cache/*