我有一个这样的测试文件夹:
[20/01/3|2:08:12][samuel@localhost:/tmp]
>>> ls test1
1.txt 2.txt 3.txt 4.txt 5.txt在普通的bash/zsh shell中,这是命令的输出
>>> rsync -avz --exclude="2.txt" --dry-run test1/ test2/
sending incremental file list
./
1.txt
3.txt
4.txt
5.txt
sent 138 bytes received 31 bytes 338.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)
[20/01/3|2:10:42][samuel@localhost:/tmp]但是在xonsh shell中,这是输出
samuel@localhost /tmp $ rsync -avz --exclude="2.txt" --dry-run test1/ test2/
sending incremental file list
./
1.txt
2.txt
3.txt
4.txt
5.txt
sent 156 bytes received 34 bytes 380.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)
samuel@localhost /tmp $我也试着用单峰来改变,但结果是一样的。
有人能解释我这个简单的命令哪里错了吗?
我的xonsh版本是0.9.11,但我也用0.9.13进行测试
发布于 2020-10-18 13:57:26
简短答覆:
--exclude "2.txt"--exclude=2.txt--exclude=@("2.txt")bash -c! find ...详细答覆:
要理解两者之间的区别,请在bash和xonsh中跟踪命令。
巴什:
set -x
rsync -avz --exclude="2.txt" --dry-run test1/ test2/
# + rsync -avz --exclude=2.txt --dry-run test1/ test2/辛什:
$XONSH_TRACE_SUBPROC=True
rsync -avz --exclude="2.txt" --dry-run test1/ test2/
# (['rsync', '-avz', '--exclude="2.txt"', '--dry-run', 'test1/', 'test2/'],)在这里您可以看到不同之处: bash删除了参数的引号,因为在bash中引号具有特殊的意义,但是xonsh将它们保留在参数中。
要使其工作,可以在xonsh中使用python替换删除引号或传递文件名:
rsync -avz --exclude=2.txt --dry-run test1/ test2/
rsync -avz --exclude=@("2.txt") --dry-run test1/ test2/另一种方法是使用xonsh 宏命令并按如下方式运行bash行:
bash -c! rsync -avz --exclude="2.txt" --dry-run test1/ test2/为了简化这种方法,有一个薛翠诗扩展,它允许在命令之前添加!符号:
! rsync -avz --exclude="2.txt" --dry-run test1/ test2/另外:
发布于 2020-01-04 06:29:26
在xonsh下运行时,没有类似于shell引用的处理。参数以原样传递给rsync程序.特别是
要排除2.txt而不是"2.txt",对'xonsh‘的命令应该是:
rsync -avz --exclude=2.txt --dry-run test1/ test2/https://stackoverflow.com/questions/59579274
复制相似问题