Valter Henrique Valter Henrique - 1 year ago 58
Bash Question

Why isn't my sed operation working?

I'm provisioning a

virtual machin
e with
This is my Vagrant output, debug mode, for my

==> mom1: + enable_https
==> mom1: ++ cat /etc/letsencrypt/live/
==> mom1: + local password=kvnilcFqq+sXmLlonoK1dM=
==> mom1: + sed -i 's,<property name="keyStorePassword" value="password" />,<property name="keyStorePassword" value="kvnilcFqq+sXmLlonoK1dM=" />,' /opt/activemq/conf/jetty.xml

It seems to be working fine, but when I check the file that was supposedly to be modified, it is empty!

<property name="keyStorePassword" value="" />

This is my Shell script:

local kpass=$(cat /etc/letsencrypt/live/
sed -i "s,<property name=\"keyStorePassword\" value=\"password\" />,<property name=\"keyStorePassword\" value=\"${kpass}\" />," /opt/activemq/conf/jetty.xml

The funny thing is that, when I try the same script locally, it works, but not when I try to use it during provision with Vagrant.

Any suggestion ? :)

Answer Source

Just for further reference, my problem was that the same file which my sed was being applied, it was modified before, by another script. Which it means, my sed was correct, indeed. However it wasn't possible to apply it over the file, since this one wasn't the same anymore.