[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Backslash missing in brace expansion
From: |
Chet Ramey |
Subject: |
Re: Backslash missing in brace expansion |
Date: |
Fri, 6 Dec 2019 09:12:28 -0800 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 |
On 12/5/19 8:53 PM, Martin Schulte wrote:
>> It's an unquoted backslash, which is removed by quote removal when the
>> words are expanded. Look at the extra space between `[' and `]'; that's
>> the null argument resulting from the unquoted backslash.
>
> Yes - sure. But then I'm wondering why the unquoted backtick doesn't
> start command substitution:
>
> $ echo {Z..a}
> Z [ ] ^ _ ` a
> $ echo Z [ \ ] ^ _ ` a
>>
It's a reasonable question. The short answer is that brace expansion
takes place after parsing and results in multiple words.
Look at it this way. When the parser is reading a simple command, it
applies certain rules (matching quotes, metacharacter recognition, etc.)
and produces a list of words, which the shell expands and executes. Brace
expansion is similar in that it takes a single word and produces a list
of words which are then run through word expansion, but it does not apply
the same rules as the parser (or any rules, really).
What you end up with is a list of words: [, \, ], ^, _, `. a .
Each of those words is expanded as usual. When you get to the word that
consists of the single character "`", the expansion code checks whether
or not it's a valid command substitution, and, finding it's a single "`"
instead, leaves it unchanged.
The single backslash, as I explained earlier, is removed, resulting in a
null word after expansion.
This is an example of how you can use brace expansion to produce words
the parser would never have passed as valid.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
- Backslash missing in brace expansion, Martin Schulte, 2019/12/05
- Re: Backslash missing in brace expansion, Chet Ramey, 2019/12/05
- Re: Backslash missing in brace expansion, Martin Schulte, 2019/12/05
- Re: Backslash missing in brace expansion,
Chet Ramey <=
- Re: Backslash missing in brace expansion, Eric Blake, 2019/12/06
- Re: Backslash missing in brace expansion, Ilkka Virta, 2019/12/06
- Re: Backslash missing in brace expansion, Chet Ramey, 2019/12/06
- Re: Backslash missing in brace expansion, Martin Schulte, 2019/12/08
- Re: Backslash missing in brace expansion, Andreas Kusalananda Kähäri, 2019/12/08
- Not missing, but very hard to see (was Re: Backslash missing in brace expansion), L A Walsh, 2019/12/12
- Re: Not missing, but very hard to see (was Re: Backslash missing in brace expansion), Greg Wooledge, 2019/12/12
- Re: Not missing, but very hard to see (was Re: Backslash missing in brace expansion), Ilkka Virta, 2019/12/12
- Re: Not missing, but very hard to see (was Re: Backslash missing in brace expansion), L A Walsh, 2019/12/12
- Re: Not missing, but very hard to see (was Re: Backslash missing in brace expansion), Eli Schwartz, 2019/12/12