I’m playing around with a tiny app (in C) that, when run, creates a directory tree which it populates with files. It does this by using a series of lines of the form
system("echo \"lump = \" >> ./newdirectory/newfile.c");
This is working fine, except for when I try to have it write a line of C into the new file which itself contains a system("echo"); call.
Specifically,
system("echo \"system(\"echo hello world\");\" >> ./newdirectory/newfile.c");
gets written as
system(echo hello world);
Since you want the escape characters to appear as-is, you need to escape them too. Yes, you can escape escape characters. Something like:
This results in outputting a
\followed by an".