[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] How to understand the blank space here
From: |
Davide Brini |
Subject: |
Re: [Help-bash] How to understand the blank space here |
Date: |
Tue, 27 Dec 2011 16:34:28 +0100 |
On Mon, 26 Dec 2011 23:02:53 +0800, lina <address@hidden> wrote:
> Hi,
>
> $ echo \"{Those, words, are, quoted}\"
> "{Those, words, are, quoted}"
>
> I have a space after ,
Here bash sees four tokens after echo:
"{Those,
words,
are,
quoted}"
The double quote is part of the first and last argument, because you escaped
it with backslash. Those four tokens become arguments to echo, which
outputs them with a space in between them. Just as if you did
echo a b c d
you'd get
a b c d
as output.
>
> echo \"{Those,words,are,quoted}\"
> "Those" "words" "are" "quoted"
>
> Just wonder why the space there changed things,
Here you're seeing a different thing. This is brace expansion. First of
all, since there are no spaces, you're now creating a single token:
"{Those,words,are,quoted}"
The way brace expansion works is that each comma-separated word is
expanded to a separate argument; however, the brace expansion includes a
preamble (a double quote) and a postscript (again a single quote), so the
preamble and the postscript are prepended/appended to each of the generated
arguments, which is what echo finally sees. You can probably see it better
if you do this:
$ echo preamble_{a,b,c,d}_postscript
preamble_a_postscript preamble_b_postscript preamble_c_postscript
preamble_d_postscript
The only difference is that in your case both the preamble and the
postscript are " (double quote).
--
D.