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


If I execute this in Bash

echo "1 2"

I get 1 2. But if I execute

echo \"1 2\"

I get "1 2".

Now I would figure if I execute

echo $(echo \"1 2\")

I would get 1 2. But again, I get "1 2". In fact, no matter how many command substitutions in the chain

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

I always get "1 2". Why is that?


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 <a href="http://www.gnu.org/software/bash/manual/bashref.html#Quote-Removal" rel="nofollow">Quote Removal</a>:


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.


  • How to configure ExecStart for Gunicorn without WSGI?
  • How to escape wildcard expansion in a variable in bash?
  • Bash : Adding extra single quotes to strings with spaces
  • Cronjobs in Docker container how get them running?
  • How to get rid of enclosing double-quotes in the expanded `forfiles` variables?
  • How to avoid this Apple Siri https cracking scenario?
  • How can I find the installation directory of a specific program?
  • Brackets ${}, $(), $[] difference and usage in bash [duplicate]
  • Whats the best approach to use q promise in a loop? Waiting for chain to complete before iterating t
  • Access VBScript variable within Javascript inside of an HTA
  • How to convert list into string with quotes in python
  • MySQL wildcard replace
  • How java deals with references to a generic type
  • How to prepare a C++ string for sql query
  • Deserialize Dictionary
  • LNK1104: cannot open file 'kernel32.lib'
  • Python: Split a String Field into 3 Separate Fields using Lambda
  • Generic classes with Collection getter of other types
  • how can I compare dates in array to find the earliest one?
  • Divide a $1 by 3 and adjusting 1 cent
  • ckeditor and jquery UI dialog not working
  • Most efficient way to move table rows from one table to another
  • jQuery: How to AJAXify WordPress Search?
  • How do I shift the decimal place in Python?
  • Regex to match a string not followed by anything
  • Mysql - How to search for 26 records that each begins with the letter of the alphabet?
  • How does document.ready work with angular element directives?
  • Parse a date string in a specific locale (not timezone!)
  • Declaring variable dynamically in VB.net
  • Lost migrations and Azure database is now out of sync
  • Using $this when not in object context
  • Master page gives error
  • How do I fake an specific browser client when using Java's Net library?
  • How reduce the height of an mschart by breaking up the y-axis
  • Join two tables and save into third-sql
  • Perl system calls when running as another user using sudo
  • Deserializing XML into class C#
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • python draw pie shapes with colour filled
  • How to Embed XSL into XML