Search code examples
bashdouble-quotes

Recursive Quotation


When writing bash scripts is there a third level of recursion for double quotes? I need to use double quotes since single quotes will read variables literally.

I can do

"first level \"second level\""

But would like to do something like

"first level \"second level \\" third level \\"\""

I see why that does not work but I need help with syntax


Solution

  • You have to escape the backslash as well.

    "first level \"second level \\\" third level \\\"\""
    

    The first \\ makes a literal backslash, then \" escapes the double quote.