Skip to content
Advertisement

How to make a return from a child function cause a return to the parent function?

I have a parent function and child function:

JavaScript

How to make the return 1 (of the child) cause a return in the parent and then avoid the execute the remaining child calls?

without adding a check of the returned value after each child call like this

JavaScript

Advertisement

Answer

There is a solution other than set -e and || return

It’s simple, just use exit instead of return and the parent should called in a sub-shell:

JavaScript

And I call the parent in this way:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement