[Top][All Lists]

[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: Mon, 07 Jan 2019 16:15:41 +0700

    Date:        Sun, 6 Jan 2019 17:22:36 -0500
    From:        Chet Ramey <address@hidden>
    Message-ID:  <address@hidden>

  | Bash, in its default mode, considers errors from builtins non-fatal. When
  | you run this in posix mode, which makes a distinction between "special" and
  | "regular" builtins, it should be a fatal error because POSIX says a non
  | interactive shell needs to exit if a special builtin fails. It's a bug in
  | bash if it doesn't do that in posix mode.

But return is not required to fail if it does not appear in a function or . 
script, what POSIX says is ...

        The return utility shall cause the shell to stop executing the current 
        or dot script. If the shell is not currently executing a function or 
dot script,
        the results are unspecified.

That means that bash (or any other shell) can do whatever it likes (but
should document what it does) when a return happens other than in a
function or dot script.

Making it an error is fine, making it == exit is fine, having it set $? and
otherwise do nothing is fine, or simply ignoring it completely is fine.

Amy script that contains "return" must be executed as ". script" for it
to expect anything at all - it is certainly not to be expected that such
a script can be executed as "sh script" (for any 'sh') and do anything
rational at all.


reply via email to

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