2

I have this bash code

REPLACEMENT="s:define('CP_DIRECTORY.*:define('CP_DIRECTORY), ('"${NEWLOCATION}"');:;"
sed -i $REPLACEMENT $INITDATA;

It returns

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

I am trying to replace a line in initdata.php that looks like this:

define( 'CP_DIRECTORY', 'admin' );

to this

define( 'CP_DIRECTORY', 'AJgBCecvPBUnPZCLvKukyzfehWrsF5wI' );
simont
  • 68,704
  • 18
  • 117
  • 136
David Diaz
  • 148
  • 1
  • 12

2 Answers2

2

Put single quotes around the entire sed command:

sed -i 's:AdminCP = .*:AdminCP = "/home/pi/forums/AJgBCecvPBUnPZCLvKukyzfehWrsF5wI";:' forums/initdata.php

Otherwise, the command is split on the spaces. Also, you need a dot before the asterisk, otherwise you're just saying "zero or more spaces".

Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439
  • @DavidDiaz: Your question had none of that in it. Why didn't you post what you're actually trying to do. Please edit your question so it reflects your actual conditions. – Dennis Williamson Jul 11 '12 at 04:12
  • Updated, sorry. I saw this earlier and I tried to edit it but my internet kept on cutting out due to extreme packet loss so I just commented. – David Diaz Jul 11 '12 at 04:31
0

Got it to work thanks to Dennis Williamson saying that I needed to quote the sed command & http://www.linuxquestions.org/questions/linux-software-2/sed-with-bash-variables-304260/

Final code was

    REPLACEMENT="define( 'CP_DIRECTORY' ), ( '"
    REPLACEMENT=$REPLACEMENT$NEWLOCATION;
    REPLACEMENT=$REPLACEMENT"' );:;";
    sed -i "s:define( 'CP_DIRECTORY.*:$REPLACEMENT" $INITDATA;
David Diaz
  • 148
  • 1
  • 12