0

Im having an issue with this code in the command line:

sed -i 's/row['email']/_SESSION['nen']/g' /var/www/v2-stage/v2-stage/add_on/change_password.php

For some reason i think it isnt working since the 'email' but that is how the code is & i cant change it. Also im running it through the shell_exec for php. but i tried it directly and it wasnt working as well.

any ideas?

john
  • 157
  • 2
  • 12
  • 1
    you'd need to escape your inner quotes – Devon Bessemer Jul 19 '18 at 13:42
  • Look at the color of the highlighted code. Notice anything? You're trying to use single quotes inside of a single-quoted string. – Jonathon Reinhart Jul 19 '18 at 13:42
  • @JonathonReinhart *"For some reason i think it isnt working since the 'email'"* I think they're well aware of it – Federico klez Culloca Jul 19 '18 at 13:44
  • 2
    *"It is not working"* is not a good problem statement. Possible duplicate of [What characters do I need to escape when using sed in a sh script?](https://unix.stackexchange.com/q/32907/56041), [Escape a string for a sed replace pattern](https://stackoverflow.com/q/407523/608639), [How do I escape double and single quotes in sed?](https://stackoverflow.com/q/7517632/608639), [How to escape single quote in sed?](https://stackoverflow.com/q/24509214/608639), etc. – jww Jul 19 '18 at 13:49
  • Okay but i dont know how to escape my inner quotes this is why i posted the question! – john Jul 19 '18 at 14:00

1 Answers1

2

Because you have ' in your command, you need to use double quote " for sed.

Any char except ' will be literal (which means the \ will be literal, too), so you can rewrite your command as

sed -i "s/row\['email'\]/_SESSION['nen']/g" /var/www/v2-stage/v2-stage/add_on/change_password.php

If you write your command in a text editor (or notice the color on stackoverflow), the syntax highlight will help you determine the correctness of your command.

dibery
  • 2,760
  • 4
  • 16
  • 25