Quantcast
Channel: How to enclose in quotes if both single and double quotes are already used? - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 6

Answer by aecolley for How to enclose in quotes if both single and double quotes are already used?

$
0
0

There is a simple, systematic and POSIX-compliant way to quote any string. You only need to remember two rules:

  1. Quote apostrophes (single quotes) with a backslash like so: \'
  2. 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

Viewing all articles
Browse latest Browse all 6

Trending Articles