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: Robert Elz
Subject: Re: "return" should not continue script execution, even if used inappropriately
Date: Fri, 25 Jan 2019 11:13:21 +0700

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]