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

前端 未结 1 898
清酒与你
清酒与你 2021-01-16 15:29

If I execute this in Bash

echo \"1 2\"

I get 1 2. But if I execute

echo \\\"1 2\\\"

I get

相关标签:
1条回答
  • 2021-01-16 15:38

    After substituting the output of $(command) back into the command line, the only additional parsing that's done is word-splitting and wildcard expansion. Quotes are not processed, so if the command outputs quotes they will be left in the command line as literal characters.

    This is explained in the bash manual section on Quote Removal:

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

    Since the quotes resulted from command substitution (that's one of the expansions listed before this), they're not removed.

    0 讨论(0)
提交回复
热议问题