bug-bash
[Top][All Lists]
Advanced

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

Re: "return" should not continue script execution, even if used inapprop


From: konsolebox
Subject: Re: "return" should not continue script execution, even if used inappropriately
Date: Fri, 25 Jan 2019 11:29:43 +0800

Well I didn't see any part of that discussion that describes that. Also
it's a C thing. Please don't disgrace.

-- konsolebox/m

On Fri, Jan 25, 2019, 9:20 AM don fong <dfong@dfong.com wrote:

> Encapsulate your code in a main function and deal with it.
>>
>
> yes, exactly.  and that supposedly "crazy" python convention (its bash
> equivalent) is the best way i know of to "deal with it".
>
>
> On Thu, Jan 24, 2019 at 4:08 PM konsolebox <konsolebox@gmail.com> wrote:
>
>> Encapsulate your code in a main function and deal with it.
>>
>> -- konsolebox/m
>>
>> On Mon, Jan 21, 2019, 12:39 PM Robert Elz <kre@munnari.oz.au wrote:
>>
>>>     Date:        Sun, 20 Jan 2019 17:43:04 -0800
>>>     From:        don fong <dfong@dfong.com>
>>>     Message-ID:  <
>>> CAHQakpXao-pBDR2e0tNHH_iouHLWDXQ_FcCbzo1gxRhpfv915A@mail.gmail.com>
>>>
>>>   | i don't see how this helps.  the point is to have one file of code
>>> that
>>>   | behaves differently depending on whether it's dotted in or executed
>>> at the
>>>   | top level.
>>>
>>> That's fine, if you are writing something to work like this, you
>>> just make sure that it will work when run either way.  That means
>>> rthat you cannot do a "return" outside of a function in the script.
>>>
>>> This is easy to accomplish, the code just needs to be written
>>> to meet both sets of requirements (if you want to finish in a reliable
>>> way, you execute to EOF, and don't use either exit or return).
>>>
>>>   | the script should do nothing but define stuff when dotted in;
>>>   | but call the main function (or some other function) when run at the
>>> top
>>>   | level. "sh -c '. script'" doesn't accomplish that.
>>>
>>> No, but it allows you to test a script that is not written to be able
>>> to be run either way, someone's script that is only intended to be
>>> executed as ". script" which you then want to test.    In many cases
>>> you might need to add more than just the '.' command - depending
>>> on what is in the script (as I said way back in my first message on
>>> this subject).
>>>
>>> kre
>>>
>>>
>>>


reply via email to

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