Re: shell quoting around script output



On 1/12/2012 6:23 PM, Kaz Kylheku wrote:
On 2012-01-12, Ed Morton<mortonspam@xxxxxxxxx> wrote:
Yes, I know but I don't think that answers my question of why this:

$ awk "$(cat<<"end"
BEGIN{ print "Hello World" }
end
)"

behaves like this (double quotes around $(..) replaced by single quotes):

$ awk 'BEGIN{ print "Hello World" }'

<stuff I already know snipped>
The $(...) will take the output of cat (the here document) and turn it into a
one big string, which is prevented from word splitting or globs because it
is in quotes, causing it to be passed to awk as one argument.

Is that the definitive answer then? That the script that is output from $(...) is not subject to word splitting and so is passed to awk as one argument and that is exactly the same behavior as enclosing a script in single quotes?

Or to put it another way, enclosing a script in single quotes works because that prevents word splitting, and using $(...) to generate a script works because that also prevents word splitting. Is that right?

Ed.
.