[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, lisa-asket@perso.be wrote:
> With ` set -e` the script will exit immediately if a command exits with a
> non-zero status.
Except when it doesn't.
https://mywiki.wooledge.org/BashFAQ/105
> 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
hi
0
Exit statuses can be inspected with $?, if desired.
--
vq
- condition to execute, lisa-asket, 2021/07/05
- Re: condition to execute, Lawrence Velázquez, 2021/07/05
- condition to execute, lisa-asket, 2021/07/05
- Re: condition to execute, David, 2021/07/05
- condition to execute, lisa-asket, 2021/07/05
- Re: condition to execute, Greg Wooledge, 2021/07/06
- condition to execute, lisa-asket, 2021/07/06
- Re: condition to execute,
Lawrence Velázquez <=
- condition to execute, lisa-asket, 2021/07/06
- Re: condition to execute, Lawrence Velázquez, 2021/07/06
- Re: condition to execute, Eli Schwartz, 2021/07/06
- Re: condition to execute, Greg Wooledge, 2021/07/06
- condition to execute, lisa-asket, 2021/07/06