title: Why can't I echo the characters #! in a string in bash?
body: <p>I had a tiny bash script that is supposed to move to my home directory, make a file, echo some junk onto it, and make it executable. This is what it looked like:</p>
  
  <pre><code>cd ; touch tor.sh; echo "#!/bin/bash\n/usr/local/bin/tor" &gt;&gt; tor.sh; chmod +x tor.sh
  </code></pre>
  
  <p>But this kept breaking at the echo, complaining about "event not found" ? For some reason I decided to try this and it worked:</p>
  
  <pre><code>cd ; touch tor.sh; echo -e "\x23\x21/bin/bash\n/usr/local/bin/tor" &gt;&gt; tor.sh; chmod +x tor.sh
  </code></pre>
  
  <p>Why did I have to replace those two characters (the shebang?) with hex and a -e? Is there a better way to do this?</p>