Skip to content

Parsing Shell Quotes Requires Parsing the Whole Language

andychu edited this page Oct 31, 2018 · 3 revisions

This is example has four double quotes. To determine whether it means OPEN OPEN CLOSE CLOSE or OPEN CLOSE OPEN CLOSE requires a full shell parser.

$ echo "foo ${myvar:-"$(f() { echo func-defined-inside-quotes-and-inside-arg; }; f)"} bar"
foo func-defined-inside-quotes-and-inside-arg bar

$ myvar=x
$ echo "foo ${myvar:-"$(f() { echo func-defined-inside-quotes-and-inside-arg; }; f)"} bar"
foo x bar
Clone this wiki locally