bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Here strings and brace expansion not working as per man page


From: Conor McCarthy
Subject: Re: Here strings and brace expansion not working as per man page
Date: Wed, 15 Feb 2017 19:27:19 +0000

On 9 February 2017 at 20:55, Chet Ramey <address@hidden> wrote:
> On 2/8/17 3:04 PM, Conor McCarthy wrote:
>
>> Bash Version: 4.4
>> Patch Level: 12
>> Release Status: release
>>
>> Description:
>>         Here strings are documented as:
>>
>>            [n]<<<word
>>
>>         The word undergoes brace  expansion,  tilde  expansion,  parameter  
>> and
>>         variable  expansion,  command  substitution,  arithmetic expansion, 
>> and
>>         quote removal.
>>
>>         But brace expansion is not applied:
>>
>>         $ read zz <<< {1..9}
>>         $ echo $zz
>>         {1..9}
>>
>>         The codepath from write_here_string() does not pass through any
>>         expand_xxx functions which apply brace expansion, AFAICT.
>>
>>         (bash was built with -fno-inline for gdb only)
>>
>> Repeat-By:
>>         $ read zz <<< {1..9}
>>         $ echo $zz
>>         {1..9}
>>
>>         Expected behaviour would be similar to:
>>         $ read zz <<< $(echo {1..9})
>>         $ echo $zz
>>         1 2 3 4 5 6 7 8 9
>
> Thanks for the report.  This is a documentation error.  Your workaround
> is a reasonable one.

Diff attached for the curious. Consider this towards the Dr. Bunsen end
of the experimental spectrum, I'm a relative novice with bash internals.

I can't think of a compelling use case, but it does allow stupid loopless
and subshell-less tricks like:

  read az[{65..90}] <<< {A..Z}

and can be (ab)used  for shorthand array slice type operation:

  read aa[{1..5}] <<< "${az[" {69..65} "]}"

(though the absence of parameterisation for {..} makes it less useful
than it might initially appear)

Case closed, thanks!

Regards,
  Conor.

Attachment: redir.diff
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]