命令替换中的转义双引号会变成 Bash 中的文字吗?

Do escaped double quotes in command substitution become literals in Bash?

如果我在 Bash

中执行此操作
echo "1 2"

我得到 1 2。但是如果我执行

echo \"1 2\"

我得到 "1 2"

现在我想如果我执行

echo $(echo \"1 2\")

我会得到 1 2。但是,我再次得到 "1 2"。事实上,无论链中有多少命令替换

echo $(echo $( ... echo \"1 2\") ... )

我总是得到 "1 2"。这是为什么?

$(command) 的输出替换回命令行后,唯一完成的额外解析是分词和通配符扩展。不处理引号,因此如果命令输出引号,它们将作为文字字符留在命令行中。

这在 Quote Removal 的 bash 手册部分有解释:

After the preceding expansions, all unquoted occurrences of the characters ‘\’, ‘'’, and ‘"’ that did not result from one of the above expansions are removed.

由于引号是由命令替换产生的(这是之前列出的扩展之一),因此它们没有被删除。