使用shell命令从php.ini中的一行中删除分号 [英] Removed semicolon from a line in php.ini using shell command
问题描述
我想使用bash shell命令(也许使用 sed
)从php.ini中的其中一行删除分号.我该怎么办?
I'd like to removed a semicolon from one of these lines in the php.ini using bash shell command (perhaps using sed
). How would I do that?
;extension =php_curl.dll
; extension=php_gd2.dll
;extension = php_mbstring.dll
;extension= php_openssl.dll
我故意在这里和那里添加空格.
I intentionally added spaces here and there.
我尝试过的事情:
sed -e "s/^;extension\s=\sphp_gd2\.dll$/extension=php_gd2\.dll/" -i php.ini
这只是将所有内容放在一行中:
This just places everyting into a single line:
;extension =php_curl.dll ; extension=php_gd2.dll;extension = php_mbstring.dll;extension= php_openssl.dll
推荐答案
这将删除行的开头的分号,该行的两边都有一个或多个空格
This removes a semicolon at the beginning of a line that has one or more spaces on both sides
sed'/php_gd2/s/^ \ s \ s *; \ s \ s *//'php.ini
您可以通过将其放在开头的斜杠之间来指定要操作的php扩展名.然后,它将仅在具有指定扩展名的行上运行替代命令
You can specify which php extension you want to operate on by putting it in between slashes at the beginning. Then it will run the substitute command only on the lines that have the specified extension
要更具选择性,
sed'/^\s*;\s*extension\s*=\s*php_gd2.*\.dll/s/^/s\s*;\s\s*//'php.ini
这篇关于使用shell命令从php.ini中的一行中删除分号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!