Dou*_*oug 0 linux shell-scripting
我想知道除了将每一行附加到文件之外,是否还有更好的方法来创建文件。我这样做是为了保持可读性,但是,没有缩进。有没有办法创建一个文件并一次输入多行?
if [ -d "/srv/www/$1" ]; then
echo "Domain name already exists!"
else
mkdir -p /srv/www/$1/public_html;
mkdir -p /srv/www/$1/logs;
echo "<VirtualHost>" > /etc/apache2/sites-available/$1
echo "ServerAdmin support@$1" >> /etc/apache2/sites-available/$1
echo "ServerName $1" >> /etc/apache2/sites-available/$1
echo "ServerAlias www.$1" >> /etc/apache2/sites-available/$1
echo "DocumentRoot /srv/www/$1/public_html/" >> /etc/apache2/sites-available/$1
echo "ErrorLog /srv/www/$1/logs/error.log" >> /etc/apache2/sites-available/$1
echo "CustomLog /srv/www/$1/logs/access.log combined" >> /etc/apache2/sites-available/$1
echo "</VirtualHost>" >> /etc/apache2/sites-available/$1
a2ensite $1
Run Code Online (Sandbox Code Playgroud)
使用heredoc。
cat > /etc/apache2/sites-available/"$1" << EOF
<VirtualHost>
ServerAdmin support@$1
...
EOF
Run Code Online (Sandbox Code Playgroud)