Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I keep getting this error, do you guys know what is wrong?

rapache is an alias for restart apache

mugbear:/usr/bin# cat /usr/bin/mkdomain                                         
if [ -d "/srv/www/$1" ]; then
        echo "Domain $1 already exists!"
        mkdir -p /srv/www/$1/public_html
        mkdir -p /srv/www/$1/logs
        cat >> /etc/apache2/sites-available/"$1" << EOF
        <VirtualHost removed:80>
                ServerAdmin support@$1
                ServerName $1
                ServerAlias www.$1
                        DocumentRoot /srv/www/$1/public_html/
                ErrorLog /srv/www/$1/logs/error.log
                CustomLog /srv/www/$1/logs/access.log combined
        a2ensite $1
mugbear:/usr/bin# mkdomain                                        
/usr/bin/mkdomain: line 19: syntax error: unexpected end of file
share|improve this question
up vote 3 down vote accepted

Your heredoc never ends since the terminator is not at the beginning of the line.

share|improve this answer
I don't see a terminator in the other answer:… Could you show me me an example? Also, I cannot seem to find a manual on EOF. – Doug Oct 31 '10 at 5:33
The EOF must be the only thing on the line. No spaces before, and none after. And you want to find a manual for <<, not EOF. – Ignacio Vazquez-Abrams Oct 31 '10 at 5:35
Ahh. I see, it looks weird without the indentation, but it works. Thakns! – Doug Oct 31 '10 at 5:38
Generally heredocs are not indented. It's understood that they're not really part of the script. – Ignacio Vazquez-Abrams Oct 31 '10 at 5:40
someFile <<EOF


    someFile <<EOF

will not work

    someFile <<-EOF


See 'man bash' and the Bash Reference Manual, section "3.6.6 Here Documents" for details on <<-EOF. Note that the indentation of the heredoc terminator must be done using tabs, not spaces.

share|improve this answer
Good point re: <<-EOF. I fixed your formatting and added the detail about tabs for you. – MikeyB Mar 24 '11 at 16:43
+1 for mentioning <<-EOF. Also see Bash Reference Manual, section "3.6.6 Here Documents" for an explanation. I added some links to your answer. – Stefan Lasiewski Mar 24 '11 at 16:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.