8 Temmuz 2022 Cuma tarihinde Yair Lenga <yair.le...@gmail.com> yazdı:
>
> Practical Example - real life. A job has to copy 3 critical data files. It
> then sends notification via email (non-critical).
>
> #! /bin/bash
> set -o errfail
> function copy-files {
>      # ALL files are critical, script will not cont
>      cp /new/file1 /production/path/
>      cp /new/file2 /production/path/
>      # Use the files for something - e.g., count the lines.
>      important-job /production/path/file1 /production/path/file2
>
>      ls -l /production/path | mail -s "all-good" not...@company.com ||
> true    # Not critical
> }
>
> if copy-files ; then
>      more-critical-jobs
>       echo "ALL GOOD"
> else
>       mail -s "PROBLEM" nor...@company.com < /dev/null
> fi
>
> What is the difference ? consider the case where /new/file1 does not
> exists, which is critical error.
> * Without errfail, an error message will be sent to script stderr, but the
> script will continue to copy the 2nd file, and to perform the
> important-job, even though the data is not ready.


How is this any better than doing `cp ... && cp ... && important-job ...'?


-- 
Oğuz

Reply via email to