0

I am writing a script that needs to modify the default php_admin_value[memory_limit] from 128 M to 512M. I don't get any errors when i execute the command from the CLI or from a bash script, but neither actually apply the update to the file. What am I doing wrong?

The line in the /etc/php-fpm.d/www.conf file is:

;php_admin_value[memory_limit] = 128M

Here is my the command:

sudo sed -i 's/;php_admin_value[memory_limit] = 128M/php_admin_value[memory_limit] = 512M/' /etc/php-fpm.d/www.conf

1 Answers1

1

In a sed regular expression, [ is a special character that introduces a bracket expression. In order to treat it as a literal character, it must be escaped. You can escape the closing ] as well for clarity, although it is not strictly necessary.

So whereas

$ echo ';php_admin_value[memory_limit] = 128M' | 
    sed 's/;php_admin_value[memory_limit] = 128M/php_admin_value[memory_limit] = 512M/'
;php_admin_value[memory_limit] = 128M

fails,

$ echo ';php_admin_value[memory_limit] = 128M' | 
    sed 's/;php_admin_value\[memory_limit] = 128M/php_admin_value[memory_limit] = 512M/'
php_admin_value[memory_limit] = 512M

succeeds. See also What characters do I need to escape when using sed in a sh script?

steeldriver
  • 81,074