I need to modify the content of a file, with the following sed command (which works fine):
sed -i '[email protected].*@'"date.timezone = $TZ"'@' $PHP_INI_DIR/conf.d/symfony.ini
This line should be injected in a script before the exec
:
#!/bin/sh
set -e
exec "$@"
So i need another sed to say "replace before exec
":
sed '/exec/i \sed -i '[email protected].*@'"date.timezone = $TZ"'@' $PHP_INI_DIR/conf.d/symfony.ini\n' docker-php-entrypoint
The problem are quotes which are not outputted:
#!/bin/sh
set -e
sed -i [email protected].*@"date.timezone = $TZ"@ $PHP_INI_DIR/conf.d/symfony.ini
exec
Putting a backslash \
before '[email protected]
does nothing. Any suggestion?
This is a shell issue. The shell does "quote removal", so you need to study how quotes behave in the shell. Single quotes can't be nested nor escaped. You have to end the single quoted string to insert a single quote.
You can use double quotes within single quotes and vice versa to escape the quotes:
This way, the single quotes are escaped within the single quotes and the double quotes are used within the escaped single quotes.