A common newbie error is to try this:
$ foo='abc "x y z"'
$ set -- $foo
$ echo "\$#=$# \$2={$2}"
expecting to see\
$#=2 $2={x y z}
when in fact it produces
$#=4 $2={"x}
$ declare -p foo
declare -- foo="abc \"x y z\""
By now it should be clear that there's no such thing as "nested quotes" in
the shell.
The actual result is more obvious once one considers the order of
operations:
1. Backslash is not an "escape", but rather a way of quoting just the next
single character. It is processed at the same time as single and double
quotes.
2. Quote stripping is only done ONCE, BEFORE variable expansions. Important
corollary: quotes and backslashes inside variables are always literal.
3. Exception: inside double quotes, $ and ` remain unquoted unless preceded
by backslash. During this phase, backslashes are removed (and the next char
always marked as quoted) when each precedes $ ` or another backslash.
4. After variable expansion, parts that were NOT quoted are considered for
wordsplitting and then globbing. Anything that was quoted is taken
literally.
5. Assignments are performed and/or the command or function is invoked.
(There are additional steps for redirections, assignments, and nested
expansions, but those are the important ones to illustrate this point.)
To illustrate it's worth considering that these are EXACTLY synonymous:
$ foo='a\bc "x y z"'
$ foo="a\\bc \"x y z\""
$ foo=a\\bc\ \"x\ y\ z\"
-Martin