Bash: How can I distinguish a char sign from a variable name?

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

On line: CustomLog logs/access_$site_log combined It looks like the interpreter is treating it _logas part of the $ site variable. The $ site variable is a dynamic variable. How can i fix this? I tried to break out of "_" using _$site\_, but this does not work for me.

+3
source share
1 answer

Use instead:

${site}_log

For bash, it is the same variable call with $varor ${var}. But parentheses are very convenient if you want to deal with such situations.

Another example

$ myvar="hello"
$ echo "$myvar"
hello
$ echo "$myvar5"

$ echo "${myvar}5"
hello5
+7
source

All Articles