[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: condition to execute

From: Lawrence Velázquez
Subject: Re: condition to execute
Date: Tue, 06 Jul 2021 17:06:07 -0400
User-agent: Cyrus-JMAP/3.5.0-alpha0-531-g1160beca77-fm-20210705.001-g1160beca

On Tue, Jul 6, 2021, at 8:07 AM, wrote:
> With ` set -e` the script will exit immediately if a command exits with a
> non-zero status.

Except when it doesn't.

> I suppose it makes sense to exit a function with a proper exit status.

Even if you do not care about the exit statuses of arbitrary pipelines
in the middle of programs, you should make sure your programs exit
with the correct status themselves.

> One might also convert the `return` statement to an `echo` statement - 
> that way the function output
> could be captured using $() braces, 
> What do you think?

I think this does not make any sense.  Replacing a 'return' with
an 'echo' would cause your function to terminate with the wrong
exit status and possibly alter its control flow.  Programs should
not print their exit statuses, anyway. Imagine this.

    $ printf '%s\n' hi

Exit statuses can be inspected with $?, if desired.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]