0

I'm coding a BASH script to automatically configure virtual hosts of an apache server. To create the virtual host configuration file I use the cat command. The problem is that I don't know how to escape the ${APACHE_LOG_DIR} variables. I tried with \$ like this :

#!/bin/bash
cat >/etc/apache2/sites-available/site1.com.conf <<EOF
<VirtualHost *:80>
     ServerAdmin webmaster@localhost
     ServerName site1.com   
     ServerAlias site1.com
     DocumentRoot /var/www/ site1.com /public_html
     ErrorLog \${APACHE_LOG_DIR}/error.log
     CustomLog \${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<Directory "/var/www/site1.com">
     AllowOverride All
</Directory>
EOF

but it doesn't work and the variable ${APACHE_LOG_DIR} is not displayed in the .conf file :

<VirtualHost *:80>
     ServerAdmin webmaster@localhost
     ServerName site1.com   
     ServerAlias site1.com
     DocumentRoot /var/www/ site1.com /public_html
     ErrorLog /error.log
     CustomLog /access.log combined
</VirtualHost>
<Directory "/var/www/site1.com">
     AllowOverride All
</Directory>

when I escape $ with \ without something after, $ appears in the .conf file, but if I escape the entire variable \${APACHE_LOG_DIR} in the code, the variable ${APACHE_LOG_DIR} no longer appears in the .conf file

Thanks for your help

Ellion
  • 1
  • 1

0 Answers0