Hello I need to replace a string but i receive error using string 'return false;'
#!bin/bash
oldstring='{alert("bash")}'
newstring='{return false;}'
grep -rl $oldstring /home/commons.bundle.js | xargs sed -i s/$oldstring/$newstring/g
error: sh deleteBoo.sh sed: espressione -e #1, carattere 25: comando `s' non terminato
bash -x yourscript
might help in some cases. Paste it at http://shellcheck.net to check for errors with automatic suggestions how to fix some problems. (Unfortunately shellcheck doesn't suggest to quote all variables.) – Bodo Feb 03 '21 at 17:24sed
fromxargs
with the output ofgrep
will likely not do what you want as the lines matching the expression given togrep
would be used as arguments, not input data, withsed
. – Kusalananda Feb 03 '21 at 17:27-l
. – Kusalananda Feb 04 '21 at 06:38