1

I am attempting to write a bash parser. Many resources have referred to this wiki

One area I am getting stuck is why the following would work

echo "$(echo "hi")"    # output => hi

According to the wiki, quotes are parsed before command substitution. In that case, why wouldn't there be an error parsing the first set of double quotes i.e."$(echo "

falky
  • 189
  • 1
    "I am attempting to write a bash parser" That's the endeavour of a lifetime. Only bash can parse the bash language. Really. Besides the complexity and inconsistence of the shell language, its dynamic nature and the fact that your supposed to parse and run a script line by line means that you cannot parse a bash script without actually running it. –  Sep 17 '20 at 13:29

1 Answers1

7

The linked article says:

all characters except for $, ", ` and \ lose any special meaning they might have

[emphasis mine]

What happens is $ in $( in your code is still special. $( ) is the syntax of command substitution. About command substitution, from the same site:

Notably, once inside a command substitution, the shell begins an entirely new quoting context. That is, double quotes inside the substitution do not match up with double quotes outside the substitution.