No, you can't really eliminate any forks, because you don't know who needs to know $? at the right time, or depends on a certain number of kids being present.
It's like any translation problem... there's the surface syntax, which might appear relatively easy to translate, but then there's the deep semantics: all the side effects of the steps. So you either have to emulate the deep semantics precisely, or you have to analyze and understand enough of the rest of the program to know what you can avoid emulating. Ugh, on either side.
| [reply] |
Indeed. $? is set by just about any command in the shell (I'm not talking csh here), including [, [[, and ((, so it can affect the entire script, not just forks. Handling this is central to the task.
| [reply] |