To give context, I'm trying to create a simple version of bash, and for that I need to mimic the way bash parses content with multiple sets of single and double quotes. I can't figure out the overall procedure by which bash handles quotes inside quotes. I noticed some repeated patterns but still don't have the full picture.
For instance this example:
$ "'"ls"'"
evaluates to:
$ 'ls'
or even this uglier example:
$ "'"'"""'"ls"'"""'"'"
evaluates to:
$ '"""ls"""'
I noticed the following patterns arise:
- if count of wrapping quotes are even it evaluates to what's inside the inverse quotes exclusively
- if count of wrapping quotes are odd it evaluates to what's inside the inverse quotes inclusively.
For example even wrapping quotes:
$ ""'ls'""
evaluates to what's inside the inverse quotes (single quotes) without the single quotes themselves, evaluation:
$ ls
Or for odd count of wrapper quotes:
$ '''"ls"'''
it evaluates to content of double quotes inclusively:
$ "ls" : command not found.
Still I don't get the full picture of how this parsing pattern for more complex quotes inside quotes is done.