help-bash
[Top][All Lists]
Advanced

[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




reply via email to

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