0

When I am executing rysnc command the exit status is 0, even though the command throws an error (code 23). I want to use the exit status code to terminate the script when there are no files found but I am not able to do so, as it gives exit status 0 only. Is there any other method so that I can terminate my script when files not found?

$ 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
    Apart from forcing an exit status of zero with true, would you want to distinguish between no files found and some files not found? – Kusalananda Apr 16 at 8:51
  • I would just want to know "no files" found as files found list would be very huge.. – Roops23 Apr 16 at 9:18
3

@Roops23, the problem is || true. Since any_code OR true will always give you 0.

So the command

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

gives the exit code as you want (namely 23)!!!

  • 1
    Note that this would give you an exit code of 23 if any file was not found. The user, in the question as well as in a comment, wants to detect when no files were found. – Kusalananda Apr 16 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.