[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
condition to execute
From: |
lisa-asket |
Subject: |
condition to execute |
Date: |
Tue, 6 Jul 2021 23:41:29 +0200 (CEST) |
>From: Lawrence Velázquez <vq@larryv.me>
>To: lisa-asket@perso.be
>Subject: Re: condition to execute
>Date: 06/07/2021 23:06:07 Europe/Paris
>Cc: help-bash@gnu.org
>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.
In elisp, I can return an object from a function using the last command in the
function.
Does this not apply to bash functions as well? Should all bash functions only
return a proper exit status and nothing else?
>$ 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, 2021/07/06
- condition to execute,
lisa-asket <=
- 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