シナリオ: sed を使用して httpd 構成ファイルの大部分を変更しようとしています。
私が試したこと:
read -d '' _OLD <<"EOF"
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
EOF
read -d '' _NEW <<"EOF"
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
EOF
echo -n ${_OLD}
echo -n ${_NEW}
sed -i "s/$_OLD/$_NEW/g" /etc/httpd/conf/httpd.conf
変更された唯一の点に気付いた場合はAllowOverride All
、ルールを変更したいだけ/var/www/html
で、他のインスタンスでは変更したくないので、そのブロック全体を調べているのです。
私が達成しようとしていることを行うには、おそらくもっと良い方法があることを知っています。方向性は大歓迎です。