its*_*pat 2 shell shell-script
我想用 .sh 文件创建一个配置文件。我不知道如何插入新行。
我已经拥有的代码:
domainconf='<VirtualHost *:80>\n ServerName '$fulldomain'\n DocumentRoot '$fullpath'\n </VirtualHost>'
echo $domainconf > /etc/apache2/sites-available/"$fulldomain".conf
Run Code Online (Sandbox Code Playgroud)
如果您需要做的只是将配置写入文件,那么以下内容将更具可读性,并且不需要变量:
cat >/etc/apache2/sites-available/"$fulldomain".conf <<END_CONFIG
<VirtualHost *:80>
ServerName '$fulldomain'
DocumentRoot '$fullpath'
</VirtualHost>
END_CONFIG
Run Code Online (Sandbox Code Playgroud)
如果您绝对需要变量中的东西:
conf=$(cat <<END_CONFIG
<VirtualHost *:80>
ServerName '$fulldomain'
DocumentRoot '$fullpath'
</VirtualHost>
END_CONFIG
)
echo "$conf" >/etc/apache2/sites-available/"$fulldomain".conf
Run Code Online (Sandbox Code Playgroud)