Yes, the
sed command will interpret the backslash itself, and the sequences "\(" and "\)" are just "(" and ")" respectively. If you want the
sed command to treat the backslashes literally, you would have to escape each of the with another backslash. But, then the shell will see the sequence "\\" within double quotes, where the backslash keeps its special meaning, and will just replace those two characters with a single backslash. The way you are using single and double quotes, the shell will be also doing that when setting the
COMM variable. You can prevent that by reversing your usage of single and double quotes (and getting rid of that useless use of "
echo" is a good idea too).
Code:
COMM='find /path/to/dir -type f \\( -name "*.gz" -o -name "*.log" \\) -mtime + ${days} -exec rm -fr {} \\;'
sed -i "/for id abc/a ${COMM}" disk.sh
(I really with this darned forum software would stop occasionally eating backslashes.)