title: passing return code to parent shell based on conditions
body: <p>I am running a wrapper within a wrapper  with the innermost having all my commands 
  Like this</p>
  
  <pre><code> L4.ksh # topmost wrapper 
      L3.ksh 
          L2.ksh 
             Nohup command &gt; log 2&gt;&amp;1&amp; # label that c1
             Nohup command &gt; log 2&gt;&amp;1&amp; # c2
             wait                      # w1
             Nohup command &gt; log 2&gt;&amp;1&amp; # c3
  
  
          L2_1.ksh
             Nohup command &gt; log 2&gt;&amp;1&amp; # label that c4
             Nohup command &gt; log 2&gt;&amp;1&amp; # c5
             wait                      # w2
             Nohup command &gt; log 2&gt;&amp;1&amp; # c6
  </code></pre>
  
  <p>what I want to do is capture exit status of C6 and C3. of course I will stick a rc=$? below it .Ok just did that . 
  Next -I want that when ALL commands L2 get over at that time Look at the status of C3 which is the LAST nohup in L2 and exit code of L2 should be that of C3 AFTER EVERYTHING in L2 has completed . Note these  C1 C2 etc are all  run in parallel. 
  When L2 finishes I will execute L2_1 the same way only after L2 finishes completely that is all processes in it finish off ( so C3 could have finished and C1 C2 are still running 
  - but all C's should finish off is the reqd. criteria ) 
  Finally if the status codes of L2 and L2_1 are both 0 then L3 should return 0 else l3 should return non zero status code.</p>
  
  <p>if I put capture the $? of the last command in L2 series ( C3 and C6 ) and  then put wait and then exit $rc </p>
  
  <pre><code>            C3
              rc=$?
              wait
              exit $rc
  </code></pre>
  
  <p>for L2 and L2_1 both and then do a conditional switch  for status code of L3- would that serve the purpose ? or how best can it be done 
  ty
  sam</p>
  
  <p>Thanks Dogbane for your reply to capture individual PID's. The problem is that I dont know how many shells get fired. L2.ksh is a run-time generated shell that contains commands 
  so the question is how do I collect all PID's.I'd have to start some counter ? to keep track.
  Isn't there a better way of finding out the status when all background tasks have finished their work in a shell and then  flag exit status of the last background task fired ?</p>