我遇到了一种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对此表示“错误:错误的命令行”。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句