0

Here my run.sh file:

#!/bin/sh

before=$(cat <<EOF
require SYSPATH.'core/Bootstrap'.EXT;
EOF
)

after=$(cat <<EOF
if(strpos($_SERVER['SCRIPT_NAME'], 'phpunit'){
sometext # <= without it works fine!
EOF
)

sed -i.bak "s|$before|$after|g" "$2"

error

sed: -e expression #1, char 79: unterminated `s' command

Works fine but I want replace multiline text!

#!/bin/sh

before=$(cat <<EOF
require SYSPATH.'core/Bootstrap'.EXT;
EOF
)

after=$(cat <<EOF
if(strpos($_SERVER['SCRIPT_NAME'], 'phpunit'){
EOF
)

sed -i.bak "s|$before|$after|g" "$2"

marked as duplicate by Stéphane Chazelas sed Feb 9 '17 at 15:26

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You probably want cat << 'EOF' instead of cat << EOF if you don't want $_SERVERS to be expanded to the content of the $_SERVERS shell variable. – Stéphane Chazelas Feb 9 '17 at 15:29
0

This fixed it:

if(strpos($_SERVER['SCRIPT_NAME'], 'phpunit'){ \n \ # <= BACKSLASH needed!
sometext

Not the answer you're looking for? Browse other questions tagged or ask your own question.