You can try one of these solutions:
echo 'option domain-name "'"$var9"'";' >> dhcpd.conf
echo "option domain-name \"$var9\";" >> dhcpd.conf
printf 'option domain-name "%s";' "$var9" >> dhcpd.conf
However, I'd rather recommend to use a pre-defined template (separated file) and replace the relevant variable occurrences with sed
, perl
or maybe mustache
, rather than doing something like echo ... $var9 ... >> dhcpd.conf
.
For example, using the Bash implementation of mustache, mo:
# Create demo file
cat > demo.mo <<EOF
option routers {{var1}};
option domain-name "{{var9}}";
EOF
# Install mustache for Bash
curl -fsSL https://git.io/get-mo -o mo
# inspect the bash script "mo" so downloaded,
# then add the executable flag
chmod +x mo
# and put "mo" in your PATH, e.g.: sudo mv mo /usr/local/bin/
# Use mustache
var1="Démo_var_1" var9="Démo var 9" mo demo.mo > demo.txt
then you obtain:
demo.txt
option routers Démo_var_1;
option domain-name "Démo var 9";
There is also a Python version in PyPI: pystache.
But of course, there are many open-source programs that provide a similar feature.
For example, as mentioned by @CharlesDuffy, the envsubst
program could also be used, relying merely on gettext
, see e.g. these references: