Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
bash脚本中的7z赢得';不排除目录_Bash_7zip - Fatal编程技术网

bash脚本中的7z赢得';不排除目录

bash脚本中的7z赢得';不排除目录,bash,7zip,Bash,7zip,我遇到过7z的一种奇怪的行为(或者bash,我还不知道)。 使用以下脚本: #!/bin/bash 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 a

我遇到过7z的一种奇怪的行为(或者bash,我还不知道)。 使用以下脚本:

#!/bin/bash
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);
$command
此外,最后两行可以很容易地替换为一行:

/usr/bin/7z a $lst1 -v2048M arch0.7z /home/user
我也试过:

command="/usr/bin/7z a  $lst1  -v2048M arch0.7z /home/dh ;"
我收到一个“arch0.7z”文件,但仍包括文件夹.config和.cache,同时:

#!/bin/bash
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 ;"
生成包含正确排除的文件夹的文件

所以,我想知道,从变量展开的行之间的区别是什么:

/usr/bin/7z a $lst1 -v2048M arch0.7z /home/user
我输入的是:

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

7z工作流程有如此重大的变化吗?

这是我没有预料到的

lst1=' -xr@/home/me/exclude_list2.lst -xr!'*.config/*' -xr!'*.cache/*' -xr!'*.local/*' '
7z a $lst1 -v2048M arch0.7z /home/me
当我在思考-xr!中的单引号时,请执行此技巧。config/'将结束变量赋值,它实际上是参数的一部分。 另外,如果我的变量是数组,那么它也可以很好地工作

顺便说一句,用“!”转义是行不通的,7z对它说“错误:错误的命令行”

不要试图在变量中插入带引号的字符串。它不起作用。相反,将这些参数粘贴到数组中,它可能会起作用。还可以查看两个脚本的
set-x
输出,您应该可以看到它们的区别。