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: Dennis Williamson
Subject: Re: "return" should not continue script execution, even if used inappropriately
Date: Sun, 6 Jan 2019 16:58:59 -0600

On Sat, Jan 5, 2019, 4:05 PM Robert Hailey <address@hidden wrote:

>
> To the most excellent bash maintainers:
>
> I have found, what I consider to be a bug, in the following version of
> bash:
> * bash-4.4.23-1.fc28.x86_64
>
> It is related to this error message:
> * "return: can only `return' from a function or sourced script"
>
> When used inappropriately (such as running a correctly-written script
> that was merely intended to be sourced rather than executed), the
> return statement does not cease execution, and "falls through" to
> continue executing the script beyond the point that the author of the
> script clearly indicated that it should cease into realms of arbitrary
> and unexpected code paths.
>
> Best wishes, kind regards, and heartfelt thank-you for your
> dedicated service to the community.
>
> --
> Robert Hailey
>


You should be able to protect yourself from this by detecting if a script
is not being sourced when it's intended that it must be and acting
accordingly.

You could also do the following if you want a script to work under either
condition:

return 2>&1 || exit

Or substitute another action for exit. Note that I'm ignoring possible
caveats.

>


reply via email to

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