Regex Sed command replacement
In my php.ini I have
error_reporting = E_ALL
I want to change it to
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
with sed command
sed -i "s/^error_reporting = .*/error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT/" /etc/php5/apache2/php.ini
I get a different result:
error_reporting = E_ALL error_reporting = E_ALL ~E_DEPRECATED error_reporting = E_ALL ~E_STRICT
but it should be
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
BTW, the sed command is in the bash script.
+3
Iori
source
to share
1 answer
&
has special meaning in the sed command's replacement entry s
; it is replaced with the matching string. You should avoid this:
sed -i 's/^error_reporting = .*/error_reporting = E_ALL \& ~E_DEPRECATED \& ~E_STRICT/' /etc/php5/apache2/php.ini
+10
Wintermute
source
to share