title: Shell script to append new lines to etc/hosts and Apache httpd-vhosts.conf in Mac OSX 10.6
body: <p>I am using Mac OSX 10.6 and doing web development on it. I know a small amount about writing shell scripts, but I am not really versed in them as of yet.</p>
  
  <p>What I would like to do is to write a shell script that will simply ask for a local site alias and the document directory and it will then append the new alias onto hosts with something like "127.0.0.1 mysite.local" on a new line at the bottom of etc/hosts.</p>
  
  <p>Then the script would append Apache's httpd-vhosts.conf file with something like this:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      DocumentRoot "/Repositories/myproject/mysite.com/trunk/htdocs"
      ServerName mysite.local
      ServerAlias mysite.localhost
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>Then it would finally run the command to restart my Apache server. Now I know the terminal command to restart Apache, that is simple enough. I also know how to read in the site name and path from the user running the script. Such as below:</p>
  
  <pre><code>#!/bin/bash
  read -p "New local site name: " site
  read -p "Site path (ex:/Repositories/myproject/mysite.com/trunk/htdocs): " sitepath
  </code></pre>
  
  <p>What I don't know how to do is to append text to a file from terminal.</p>
  
  <p>Any thoughts or helpful ideas?</p>
  
  <p>Thanks,
  Patrick</p>