[英]Xonsh and rsync command
我有一個這樣的測試文件夾:
[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測試
在 xonsh 下運行時,沒有類似於 shell 引用的處理。 參數按原樣傳遞給rsync
程序。 特別是,'--exclude="2.txt"' 將通過引號傳遞給 rsync。
要排除2.txt
,而不是"2.txt"
, 'xonsh' 命令應該是:
rsync -avz --exclude=2.txt --dry-run test1/ test2/
簡短的答案:
--exclude "2.txt"
--exclude=2.txt
--exclude=@("2.txt")
bash -c! find ...
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:
$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/
為了簡化這種方法, xontrib-sh擴展允許只添加!
在命令前簽名:
! rsync -avz --exclude="2.txt" --dry-run test1/ test2/
還:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.