title: Invoking bash aliases in Fabric scripts
body: <p>I have aliases in a <code>~/.bash_aliases</code> file on a remote ubuntu server. The file is loaded in the standard way from a <code>~/.bashrc</code> file, like so:</p>
  
  <pre><code>if [ -f ~/.bash_aliases ]; then
      . ~/.bash_aliases
  fi
  </code></pre>
  
  <p>That <code>~/.bashrc</code> file in turn is loaded (also in a standard way) from a <code>~/.profile</code> file which looks like this:</p>
  
  <pre><code>if [ "$BASH" ]; then
    if [ -f ~/.bashrc ]; then
      source ~/.bashrc
      echo ".profile loaded .bashrc"
    fi
  fi
  mesg n
  </code></pre>
  
  <p>I've found that my aliases were unavailable in my fabric commands, e.g. when I do this in a fabric script:</p>
  
  <pre><code>run("aliased_command")
  </code></pre>
  
  <p>I get this output:</p>
  
  <pre><code>run: aliased_command
  out: .profile loaded .bashrc
  out: /bin/bash: aliased_command: command not found
  Fatal error: run() encountered an error (return code 127) while executing 'aliased_command'
  </code></pre>
  
  <p>Now I managed to reproduce this outside of fabric by logging into the server with ssh, and running :</p>
  
  <pre><code>~# /bin/bash -l -c aliased_command 
  </code></pre>
  
  <p>from the shell (n.b. <code>/bin/bash -l -c</code> is fabric's default, see <a href="http://docs.fabfile.org/en/1.4.0/usage/env.html#shell" rel="noreferrer">here</a>) I get the same output:</p>
  
  <pre><code>.profile loaded .bashrc:
  /bin/bash: aliased_command: command not found
  </code></pre>
  
  <p>After a fair bit of searching on related topics, I read somewhere that aliases aren't exported for non-interactive shells, and I then managed to fix this using <code>/bin/bash -l -c -i</code> (<code>-i</code> sets bash to interactive mode).</p>
  
  <p>I then added the following to my fabfile.py:</p>
  
  <pre><code>env.shell = "/bin/bash -l -c -i" 
  </code></pre>
  
  <p>Now I can use aliases in my fabric commands... just great!</p>
  
  <hr>
  
  <p>So my questions are:</p>
  
  <ul>
  <li><p>Are there any problems with this solution? If so, what should I be doing?</p></li>
  <li><p>Does anyone else have a problem running aliases in their fabfiles?</p></li>
  <li><p>Is there any obvious reason why I might have this issue and others wouldn't?</p></li>
  <li><p>Can anyone point me to links etc. that describe this problem and a resolution? And also explain how they found them... : )</p></li>
  </ul>