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: Mon, 21 Jan 2019 13:41:17 -0800

Greg Wooledge, and Bize Ma, thanks.  to be clear, i wasn't asking "how to
do it", i was just trying to explain why the supposedly "crazy" or "weird"
python convention makes a lot of sense even in the bash context.

addressing this from the FAQ: "Bash can do this, but it's not a natural
style, and you shouldn't be doing it."  it does not seem unnatural to me.
and i do think people should be doing it, if they want to write testable
bash code.


On Mon, Jan 21, 2019 at 12:47 PM Bize Ma <binaryzebra@gmail.com> wrote:

> ------------------------------
> *From*: Greg Wooledge
> *Subject*: Re: "return" should not continue script execution, even if used
> inappropriately
> *Date*: Mon, 21 Jan 2019 09:01:33 -0500
> ------------------------------
>
> On Sun, Jan 20, 2019 at 05:43:04PM -0800, don fong wrote:
> >* 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.*
> https://mywiki.wooledge.org/BashFAQ/109
>
>
>
> This seems to work:
>
> [ "$BASH_SOURCE" = "$0" ] && echo "This file is meant to be sourced,
> not executed" && exit 1
> [ "$BASH_VERSION" ] || { echo "Please use bash" ; return 3; }
> [[ "${BASH_VERSINFO[0]}" -le 2 ]] && echo 'No BASH_SOURCE array
> variable' && return 2
> echo "this file seems to be sourced"
>


reply via email to

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