Parsing Shell Quotes Requires Parsing the Whole Language - oils-for-unix/oils GitHub Wiki
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
3/2020 edit: Although I guess you do not have to parse f() { }
in order to figure out that the first "
is OPEN. You only have to understand that ${
is not closed yet, which is not that hard I suppose.
TODO: Come up with some harder cases.