Score:0

sed works fine from interactive shell but not from script

de flag

Trying to enable/disable xdebug on my php-fpm docker container.

If I start an interactive shell using docker exec my_container bash then run:

sed -i 's/^#zend_extension/zend_extension/' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

or

sed -i 's/^zend_extension/#zend_extension/' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

The file /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini has the # added and removed as expected. However my script to do the same:

docker exec my_container bash -c "sed -i 's/^#zend_extension/zend_extension/' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"

Then nothing happens. I'm not using shell variables to there's no variable expansion issues as far as I'm aware.

Up til now my script has been:

docker exec -it my_container bash -c "cp /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini /tmp/xdebug.ini; sed -i 's/^#zend_extension/zend_extension/' /tmp/xdebug.ini; cp /tmp/xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"

But I would like to get to the bottom of it. It's driving me nuts.

Note: Anywhere I say docker exec my_container the my_container is actually a couple of commands in backticks to get the correct container, I just say my_container to make it more clear.

Any ideas?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.