title: bash: propagating exit code of command executed in alias
body: <p>In bash, I'd like to propagate exit code of the particular command executed in alias, so that alias call itself would return it (exit with it).</p>
  
  <p>Imagine the following example (Please note: command makes no sense, just demonstrates problem I face):</p>
  
  <pre><code>alias cda='cd \/a; exit_code=$?; echo "STATUS: $exit_code"; alias cdb='cd \/b'
  cda &amp;&amp; cdb
  </code></pre>
  
  <p>for me there are no such dirs as: <code>/a</code> and <code>/b</code> to make sure commands fail.
  I'd like to execute <code>cdb</code> alias only in case <code>cda</code> alias execution succeeded. However, as <code>echo</code> was the last command and it ended with <code>exit</code> status <code>0</code> => both are executed</p>
  
  <p>What I've tried is:</p>
  
  <pre><code>alias cda='cd \/a; exit_code=$?; echo "STATUS: $exit_code"; exit $exit_code'; alias cdb='cd \/b'
  cda &amp;&amp; cdb
  </code></pre>
  
  <p>however this exits the shell completely => not feasible for me.</p>
  
  <p>Any idea how to propagate the exit status (in my case <code>$exit_code</code>) as the alias exit status?</p>