title: Recommended method of escaping single quotes in bash - double quotes, backslashes, or something else?
body: <p>I want to append <code>alias foo='bar'</code> to the end of my bash profile directly in the command line and I know of two ways to do it - escaping the single quotes with backslashes, or enclosing the command in double quotes, namely: </p>
  
  <ol>
  <li><code>echo alias foo=\'bar\' &gt;&gt; ~/.bash_profile</code></li>
  <li><code>echo "alias foo='bar'" &gt;&gt; ~/.bash_profile</code></li>
  </ol>
  
  <p>Is one method considered "safer" than the other? Both work as expected, but what I'm wondering is if one of these methods has a lower probability of causing unexpected behaviour when used in other ways, or if there is some other recommended way of escaping single quotes (in this specific context) that is the least error-prone. </p>