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"
Nychos
  • 1
  • 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 09 '17 at 15:29

1 Answers1

0

This fixed it:

if(strpos($_SERVER['SCRIPT_NAME'], 'phpunit'){ \n \ # <= BACKSLASH needed!
sometext
Michael Mrozek
  • 91,316
  • 38
  • 238
  • 232
Nychos
  • 1