Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • Another workaround: Do something like my_func() { ( set -x; my_commands; ...; ) }; set +x; my_func; return_code=$?; set -x. It's dumb, but maybe more compact, and still prevents the parent script from prematurely existing? Commented Jul 27, 2020 at 17:04
  • Ah, Ciro had done this here: unix.stackexchange.com/a/452584/304032 Commented Jul 27, 2020 at 17:04
  • I think wait exit status 127 (i.e. the background job has already exited by the time wait is called) needs to be treated as 0. Of course, you'd lose the detection of a status 127 in the inner command, but that's the lesser of two evils, I guess. Commented Apr 13, 2023 at 11:13
  • Nice trick with the background job. However, why set -e in the generic run function? run shouldn't need it, and without it, it would more flexible by letting the caller choose (plus simpler). Commented Apr 13, 2023 at 12:52