There is a simple, systematic and POSIX-compliant way to quote any string. You only need to remember two rules:
- Quote apostrophes (single quotes) with a backslash like so:
\'
- Quote everything other than apostrophes by surrounding it with apostrophes like so:
'printf "foo\n"'
To illustrate how to use these rules together, the word don't
can be systematically quoted like this: 'don'\''t'
You can often find a more readable way of quoting strings, but when things get complicated, this is the reliable way to get the quoting you want.
The quoted form of the string in the question is:
$ echo 'cat file2.txt | sed '\''s/"//g'\'' > file3.txt ## Step 2 ' >> ~/globalLog.txt