On 2/16/22 19:32, Kang-Che Sung wrote:

Now, for an example where it makes a difference. Consider a Bash script
like this:

   # enable automatic error handling
   set -eo pipefail
   # check for string "issues" in a logfile
   cat logfile | grep issue | sort --unique

If there are no issues in the logs, grep return exit code 1 and the
shell interprets this as an error and exits itself.

Why do we need to implement a workaround in grep while you can
do this in shell to ignore the exit code of grep?

{ grep issue <logfile || :; } | sort --unique

In order to implement his suggestion, you need to only ignore exit code 1, while still allowing other exit codes to abort the script. (like a system error while reading the file)

But also, I've never seen ":" used as a command... where is that documented?  Is it equivalent to 'true'?

-Mike C
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to