Date:        Sun, 6 Jan 2019 17:22:36 -0500
    From:        Chet Ramey <chet.ra...@case.edu>
    Message-ID:  <ec0b765e-3524-1e17-b9ef-40c103ad0...@case.edu>

  | 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 
function
        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.

kre



Reply via email to