title: Bash script that edits itself
body: <p>I'm trying to write a bash script that can edit itself. The line of code I'm trying to use is:</p>
  
  <pre><code>sed "s/$STRING_TO_REPLACE/$NEW_STRING/" &lt; $0 &gt; $0
  </code></pre>
  
  <p>But after running the script I end up with an empty file. Any suggestions?</p>
  
  <p>I am creating a script that has two variables that contain default values. The only problem is, these default values will be different for each of the many stations where it will be used. I would rather none of the people running these stations had to open the script and edit the defaults themselves, so I want to include the ability to change the defaults in the script. One of the requirements I have is that the script must be self contained; no other files are to accompany the script and there are to be no environment variables. This would require the script to be able to edit itself.</p>