On Thu, Feb 17, 2022 at 12:50 PM Michael Conrad <mcon...@intellitree.com> wrote: > > 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)
{ grep issue <logfile || if [ "$?" -eq 1 ]; then true; fi; } | sort --unique > But also, I've never seen ":" used as a command... where is that > documented? Is it equivalent to 'true'? https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.71/html_node/Limitations-of-Builtins.html Look for the "true" section. _______________________________________________ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox