title: How to pass exit code to a function in bash?
body: <p>let's say I have this logging function in bash .</p>
  
  <pre><code>function report {
      echo "Log message: [$@]  time:  " `date` &gt;&gt; reports.txt
  }
  </code></pre>
  
  <p>And I call it each time I need like this. </p>
  
  <pre><code>report running python 
  python3 script.py 
  report python script ended
  </code></pre>
  
  <p>Now, I would also like to the log message the exist code from <code>script.py</code> </p>
  
  <p>I could obviously do this using <code>report python script ended with $? exit code</code> 
  but is there a way not to explicitly pass the argument like that, and instead fetch it from withing the function report? </p>
  
  <p>I tried  </p>
  
  <pre><code>...
  echo "Log message: [$@]  time:  " `date`  with exit code $? &gt;&gt; reports.txt
  ... 
  </code></pre>
  
  <p>but I always get <code>0</code> even if the script failed. </p>