Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15699 > unrolled thread

Re: Backslash missing in brace expansion

Started byChet Ramey <chet.ramey@case.edu>
First post2019-12-06 09:12 -0800
Last post2019-12-06 09:12 -0800
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Backslash missing in brace expansion Chet Ramey <chet.ramey@case.edu> - 2019-12-06 09:12 -0800

#15699 — Re: Backslash missing in brace expansion

FromChet Ramey <chet.ramey@case.edu>
Date2019-12-06 09:12 -0800
SubjectRe: Backslash missing in brace expansion
Message-ID<mailman.417.1575652363.1979.bug-bash@gnu.org>
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/

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web