次のコマンドを使用して、nginx.confに文字列を追加します。

次のコマンドを使用して、nginx.confに文字列を追加します。

include /etc/nginx/sites-enabled/*.confこの文字列をファイルに追加する必要がありますnginx.conf。次のようにする必要があります。

. . .
. . .

http {

    . . .
    . . .

    include /etc/nginx/conf.d/*.conf;
    # INCLUDE STRING HERE VIA COMMAND

}

いくつかのスクリプトを作成したいのですが、このステップで停止して、どのコマンドがそのタスクを実行するのかわかりません。

ベストアンサー1

特定の内容を追加できます。模様そしてsed

使用法構文/pattern/ a <string>:

sed '/include.*conf/ a "New string"'

このように:

echo "http {

    . . .
    . . .

    include /etc/nginx/conf.d/*.conf;

}" | sed '/include.*conf/ a "New string"'
http {

    . . .
    . . .

    include /etc/nginx/conf.d/*.conf;
"New string"

}


特定の位置に取り付けたい場合場所、以下を使用してください(例:)。

echo "http {

    . . .
    . . .


}" | sed '4 a\
    include /etc/nginx/sites-enabled/*.conf'
http {

    . . .
    . . .
    include /etc/nginx/sites-enabled/*.conf


}

...4行目の後に追加されました。


sedバージョン:

sed (GNU sed) 4.4

おすすめ記事