rsync 命令的退出状态

rsync 命令的退出状态

当我执行rysnc命令时,退出状态为 0,即使该命令抛出错误(代码 23)。我想在没有找到文件时使用退出状态代码来终止脚本,但我无法这样做,因为它仅给出退出状态 0。有没有其他方法可以在找不到文件时终止脚本?

$ rsync -a --files-from=test.txt . tmp || true
  rsync: link_stat "/home/user/a.txt" failed: No such file or directory (2)
  rsync: link_stat "/home/user/b.txt" failed: No such file or directory (2)
  rsync: link_stat "/home/user/c.txt" failed: No such file or directory (2)
  rsync: link_stat "/home/user/d.txt" failed: No such file or directory (2)
  rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1196) [sender=3.1.2]
$ echo $?
  0

答案1

@Roops23,问题是|| true。因为any_codeORtrue总是给你 0。

所以命令

$ rsync -a --files-from=test.txt . tmp

给出你想要的退出代码(即23)!!!

相关内容