[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 <bash@osndok.com 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.
>
- "return" should not continue script execution, even if used inappropriately, Robert Hailey, 2019/01/05
- Re: "return" should not continue script execution, even if used inappropriately, Chet Ramey, 2019/01/06
- Re: "return" should not continue script execution, even if used inappropriately,
Dennis Williamson <=
- Re: "return" should not continue script execution, even if used inappropriately, Robert Elz, 2019/01/07
- Re: "return" should not continue script execution, even if used inappropriately, Robert Elz, 2019/01/07
- Re: "return" should not continue script execution, even if used inappropriately, Greg Wooledge, 2019/01/07
- Re: "return" should not continue script execution, even if used inappropriately, Robert Elz, 2019/01/07
- Re: "return" should not continue script execution, even if used inappropriately, don fong, 2019/01/09
- Re: "return" should not continue script execution, even if used inappropriately, Robert Elz, 2019/01/10
- Re: "return" should not continue script execution, even if used inappropriately, don fong, 2019/01/20
- Re: "return" should not continue script execution, even if used inappropriately, Greg Wooledge, 2019/01/21