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: don fong
Subject: Re: "return" should not continue script execution, even if used inappropriately
Date: Thu, 24 Jan 2019 21:12:01 -0800

>
> This is also simple.   He's just not listening to the answers


that's not only an unwarranted personal attack, but it's untrue.

the "answers" have mostly been about "how to do this".  however as i've
stated multiple times: i'm not asking how to do it, i'm explaining why this
technique which is denigrated in the bash FAQ is a good one and should be
more widely used.  since someone dismissed it as the product of "crazy
python people", i've been trying to explain why it is not crazy, and why
the alternative solutions posted by you are less satisfactory.

and is
> insisting on doing it how some python FAQ answer says can be
> done, but which also says not to do...


as you well know it's from a bash FAQ, bashFAQ/109
<https://mywiki.wooledge.org/BashFAQ/109> .

If the script demands args, then it can give a usage message,
> and it can be run again as a standalone command (since passing
> args to a '.' script is non standard).   Or they can just be given to
> the script as

        sh -c '. scriptname' scriptname arg arg arg


that's either a terrible user experience, or requires a separate wrapper
script which would lose the advantages of a single self-contained file.








On Thu, Jan 24, 2019 at 8:24 PM Robert Elz <address@hidden> wrote:

> Please, both of you, stop top posting, it is anti-social, rude,
> and just lazy.
>
> If you go back to the original question (Jan 6) it was about
> a script that did "return" which did not stop the script executing
> whenencountered when the script was run as a command rather
> than via ".".
>
> It was later explained that the script in question came from
> elsewhere and could not be changed.
>
> To that the answer is simple, run it via ".".   If you don't know
> enough about the script to know how it should be run, you get
> the same answer, run it via "." (which can easily be done as
> "sh -c '. scriptname'")
>
> If the script demands args, then it can give a usage message,
> and it can be run again as a standalone command (since passing
> args to a '.' script is non standard).   Or they can just be given to
> the script as
>         sh -c '. scriptname' scriptname arg arg arg
>
> There is nothing difficult about any of this.   The only issue was the
> surprise that "return" in a script that is not run via '.' and is not in
> a function does not cause the script to exit ... but that's just how
> it was originally defined, and now what happens is unspecified,
> so it simply is *never* safe to assume anything about such a thing.
>
> Don Fong's messages went off on a tangent about how a script could
> both be usable via '.' and standalone - which is a fine objective.
>
> This is also simple.   He's just not listening to the answers and is
> insisting on doing it how some python FAQ answer says can be
> done, but which also says not to do...
>
> kre
>
>
>


reply via email to

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