Discussion:
[Help-bash] set -e and CMD_IGNORE_RETURN question
Kolya
2018-03-07 16:18:25 UTC
Permalink
Hello!

I have many troubles, when call function inside test statement, or
something like this:

set -e

f() {

    false

    echo 1

}

f && echo ok

if [ "$(f)" == "1" ] ...


Generally, i do not want "echo 1" execute, i want catch "false" by set -e.

I understand the mail logic of how it work.


I look in source, bash set CMD_IGNORE_RETURN option and not possible to
drop it down. It require, because bash executor always call err_trap
when get error.


Question is: this is bash-interpreter coding problem only, or something
else? Can me (or someone) do new option, like set -e, what won't be
ignored inside functions? (maybe need do something like
exception-handling, or other ways). Or this is conceptual problem and
this option newer can be implemented?


Thanks!
Greg Wooledge
2018-03-07 19:44:19 UTC
Permalink
I have many troubles, when call function inside test statement, or something
set -e
http://mywiki.wooledge.org/BashFAQ/105
f && echo ok
The -e will not trigger during f because this is not a simple command.
I understand the mail logic of how it work.
I don't understand what "mail logic" means.
Question is: this is bash-interpreter coding problem only, or something
else?
It is how POSIX defines set -e to work, which is based on the historical
usage of this misfeature. It is not what you think it is. It exists
only to support the continued lurching and shambling of legacy scripts.
Can me (or someone) do new option, like set -e, what won't be ignored
inside functions?
Sure! It's called doing the actual work yourself.


f() {
critically-important-command || return 1
command-that-depends-on-previous-command-success
}

f && echo ok


Error checking in languages like bash and C is done by YOU, the
programmer. There are no automatic features for it. Put those checks
in yourself.

Once again, please see http://mywiki.wooledge.org/BashFAQ/105
Chet Ramey
2018-03-08 20:02:26 UTC
Permalink
Post by Greg Wooledge
It is how POSIX defines set -e to work, which is based on the historical
usage of this misfeature. It is not what you think it is. It exists
only to support the continued lurching and shambling of legacy scripts.
set -e still exists to support `make' and `make -i'. I was reminded of this
plenty of times before the Posix text got fixed a few years back.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU ***@case.edu http://tiswww.cwru.edu/~chet/
Loading...