場景:嘗試使用sed修改大部分httpd配置文件。sed替換爲大文本
我已經試過什麼:
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
而不是其他實例因此,爲什麼我期待在這整個街區。
我知道有可能是一個更好的方式做什麼,我試圖完成。方向將不勝感激。
如果設置AllowOverride未在/ var/www/html等規則出現,這種表達可能會改變以後的規則。 –
@Stephen:好點。但是,OP似乎現在知道文件中的內容。這似乎並沒有工作,要麼和糾正我,如果我用這個錯誤'sed的「/ <目錄 「\ /無功\/WWW \/HTML」> /,/的AllowOverride/S /設置AllowOverride無/的AllowOverride – Scott
@Scott所有/'/ etc/httpd/conf/httpd.conf'實際上輸出整個文件,不改變文件的實際文本。 – Peter