Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: err_return inside function who's return value is checked



On Dec 30,  2:52am, Russell Harmon wrote:
}
} why does the following print hello?
} 
} (){ setopt err_return; false; echo hello } || :
} 
} is this a bug?

It seems to be in the realm of what might be called unreliable behavior.
Compare bash 3.2, for example:

bash-3.2$ foo() { set -e; false; echo hello; }
bash-3.2$ foo || echo goodbye
hello
bash-3.2$ foo && echo goodbye
hello
goodbye
bash-3.2$ foo
[exits]

err_return is supposed to act just like err_exit, and err_exit does not
cause the shell to exit when used in a conditional expression, and so
err_return does not cause the function to return in that circumstance.

This obviously is a case where err_return might be permitted to behave
differently without causing too much consternation, but that's not how
it has been defined.



Messages sorted by: Reverse Date, Date, Thread, Author