Insert variables using cat EOF command

Sometimes it is troublesome to modify the configuration file in the container. viThe file cannot be edited without commands.

Record vithe commonly used commands when there is no

Example 1:
Adding configuration to the nginx service configuration file $hostis in the form of a variable. You only need to put the first one EOFin quotes and it will not be escaped.

cat << 'EOF' >> default.conf
location ^~ /xxx {
            proxy_set_header Host $host;
            proxy_pass https://xxxxxxxxx;
        }
EOF

Example 2:
Delete the last line of text

sed -i '$d' default.conf

Example 3:
Replace the specified content of the text.
The following command replaces the global aaa with bbb.

sed -i 's+aaa+bbb+g' default.conf

Guess you like

Origin blog.csdn.net/zhanremo3062/article/details/131480703