0

The following sed command gives a sed unterminated `s' command. It has to do with the variable that I put in ($header):

sed -i "1s~^~$header~" $1"/main.cpp"

The following is the contents of $header:

//
// Pacman.java
// etc
//
// Created by ayman at 12/06/2021
// Copyright (c) 2021 Google. All rights reserved.
//

In the sed command, I've used a different delimiter (~), but that still gives the error. Does anyone see what the problem is?

2
  • Now that the question is closed: the text used as replacement in sed's s command can't include unescaped newline characters. Each newline in the replacement must be preceded by a backslash. – fra-san Jun 12 at 11:13
  • @fra-san There is still the problem with the s(ubstitute) command s:pat:txt:, that whatever obscure character the script writer uses as :, the replacement string provided as an argument may also contain it, and therefore break unexpectedly. – Paul_Pedant Jun 12 at 13:45