简体   繁体   English

如何使用sudo,EOF和静音输出将cat或tee打击成文件

[英]How to bash cat or tee into a file, with sudo, with EOF, and with silent output

I'm basically trying to write a script that sets up a virtual host, and I can't figure out the syntax needed to output a block of code to a root protected file, and then silence the output. 我基本上是在尝试编写用于设置虚拟主机的脚本,但是我无法弄清楚将代码块输出到受根保护的文件然后静默输出所需的语法。 I've been trying something like this: 我一直在尝试这样的事情:

sudo tee /etc/apache2/other/$NAME.conf <<EOF
NameVirtualHost *:80
<Virtualhost *:80>
        ServerName $NAME.dev
        ServerAlias www.$NAME.dev
        DocumentRoot /var/www/$NAME

        <Directory "/var/www/$NAME">
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>
EOF &> /dev/null

But it doesn't suppress the output AND it includes the &> /dev/null in the file 但是它不会抑制输出,并且在文件中包含&> /dev/null

A Here document is different from a do-loop: the redirect should appear on the line with the command: Here文档不同于do循环:重定向应该在命令的行中出现:

sudo tee /etc/apache2/other/$NAME.conf &>/dev/null <<EOF
NameVirtualHost *:80
<Virtualhost *:80>
        ServerName $NAME.dev
        ServerAlias www.$NAME.dev
        DocumentRoot /var/www/$NAME

        <Directory "/var/www/$NAME">
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>
EOF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM