0

I have the below sed command:

Ctimezone="$shortName = exec('date +%Z');\
  $longName = timezone_name_from_abbr($shortName);\
  date_default_timezone_set($longName);"

sed -i 10s@.*@$Ctimezone@ /home/file.php

However this gives me the error:

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

My understanding of sed is not great so im sure its an easy fix but couldn't work it out myself.

If you need any more info let me know

Changed to:

sed -i "10s@.*@$Ctimezone@" /home/file.php

but what is put into file.php is:

= exec('date +%Z'); = timezone_name_from_abbr(); date_default_timezone_set();

not

$shortName = exec('date +%Z'); $longName = timezone_name_from_abbr($shortName); date_default_timezone_set($longName);

Henk Langeveld
  • 8,088
  • 1
  • 43
  • 57
DevWithZachary
  • 3,545
  • 11
  • 49
  • 101

1 Answers1

4

Variables get expanded in double quotes, and since $shortName isn't set, it becomes an empty string.

Escape the dollar signs: \$.

Or, if the file you're trying to modify allows exec("date +%Z"); try to switch ' and ". There's no substitution within single quotes.

Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176