-1

while using,

sed -i '122 i <button type="button" onclick="window.open('https://localhost:$ctrl','_blank')">CTRL01</button>' SCP_PortForwarding.html;

in SCP_PortForwarding.html i am getting,

<button type="button" onclick="window.open(https://localhost:10941,_blank)">CTRL01</button>

but want to print,

<button type="button" onclick="window.open('https://localhost:10941','_blank')">CTRL01</button>

where $ctrl is randomly assigned port number.

oguz ismail
  • 1
  • 16
  • 47
  • 69
Ranz
  • 1
  • 1
  • You can't include single-quotes or variable references in a single-quoted string. – Gordon Davisson Sep 19 '22 at 22:58
  • @GordonDavisson yes, you can. See [duplicate](https://stackoverflow.com/questions/3834839) – Bohemian Sep 19 '22 at 23:20
  • @Bohemian That's about double-quoted strings (where you can include double-quotes by escaping them). There's a linked question [about single-quoted strings](https://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings), but the only answers there boil down to "end the single-quoted string, then use some other quoting/escaping mode to add a literal single-quote". – Gordon Davisson Sep 19 '22 at 23:47
  • @GordonDavisson one of the answers shows how to deal with both quotes within quotes and apostrophes within apostrophes. I actually used that answer yesterday myself for just such a situation (for an alias def) – Bohemian Sep 20 '22 at 00:09

1 Answers1

1

You can try this sed

$ sed -i "122 i <button type=\"button\" onclick=\"window.open('https://localhost:$ctrl','_blank')\">CTRL01</button>" SCP_PortForwarding.html
Gordon Davisson
  • 118,432
  • 16
  • 123
  • 151
HatLess
  • 10,622
  • 5
  • 14
  • 32