I have this section in a script:
cat <<EOF >> /etc/httpd/vhosts/$site$dom.conf
<VirtualHost *:80>
ServerName $site$dom
ServerAlias www.$site$dom
DocumentRoot /site/http/travel/itn
CustomLog logs/access_$site_log combined
DirectoryIndex default.php index.php index.html index.phtml index.cgi index.htm
ScriptAlias /awstats/ /usr/local/awstats/wwwroot/cgi-bin/
<Directory /site/http/travel/itn >
AllowOverride All
</Directory>
</VirtualHost>
EOF
In the line: CustomLog logs/access_$site_log combined
It seems like the interpreter considers _log as part of the "$site" variable. The $site variable is a dynamic variable.
How can I fix it? I tried escaping the "_" by using _$site\_ but it doesn't work for me.
Instead, use:
${site}_log
For bash, it is the same calling a variable with $var or ${var}. But brackets are very handy if you want to handle these kind of situations.
Another example
$ myvar="hello"
$ echo "$myvar"
hello
$ echo "$myvar5"
$ echo "${myvar}5"
hello5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With