-1

I searched all forums but didn't find a suitable way to achieve this.

variable

result=multiline
string and 
other string

Want to convert it to

```result=multiline
string and 
other string```

means add 3 ticks at the beginning and 3 ticks at the end of the file.

I know it's possible through sed, but I think it's not working because of special characters for example tick.

Any advice is appreciated.

Rahul Sharma
  • 779
  • 2
  • 12
  • 27
  • I don't understand what's the final value of the variable, can you echo it? – Arkadiusz Drabczyk Nov 14 '22 at 19:59
  • 1
    I'm very confused by your description. Is `result` a shell variable that contains a multiline string, or do you have some other variable whose value starts with "result=multiline...", or something else? Similarly, what is the final state you're trying to achieve? Note: you cannot have a variable name that contains backticks, so changing a `result` variable to have three backticks before its name doesn't make any sense. – Gordon Davisson Nov 14 '22 at 23:10
  • I want to add ``` in the beginning and ``` at the end of the file. – Rahul Sharma Nov 15 '22 at 06:02

1 Answers1

0

Escaping backticks with \ helped.

echo $result > result.txt

echo "\`\`\`" | cat - result.txt > some-result.txt

echo "\`\`\`" >> markdown-result.txt

Rahul Sharma
  • 779
  • 2
  • 12
  • 27