I'm trying to dynamically generate table of content for my markdown files, and trying to add it into the start of my markdown files.
But the dynamically generated TOC may contains some single quote or double quote, which leads the fail of sed execution.
Is there a way that I can add these dynamically generated TOC to the beginning of file using sed? How?
Below is my script and the error info:
# filename: add_toc.sh TOC=$(./gh-md-toc $1) sed -i "1s/^/"$TOC"/" $1 # Execution ./add_toc.sh my_doc.md sed: -e expression #1, char 5: unterminated `s' command