Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Possible bug with $~pattern, (#mi)



True, beg wasn't set in first invocation. However pattern #(#mi)1 is correct:

# a="1234"; echo ${a/#(#mi)1/-}
-234

When beg is used (this time correctly):

# a="1234"; beg="#"; echo ${a/$~beg(#mi)1/-}
zsh: bad pattern: #(#mi)1

Best regards,
Sebastian Gniazdowski


On 7 October 2015 at 17:39, Peter Stephenson <p.stephenson@xxxxxxxxxxx> wrote:
> On Wed, 7 Oct 2015 17:28:04 +0200
> Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:
>> first one and third one are the same, but only first invocation works.
>> Not sure if second one should work:
>>
>>  # a="1234"; beg="#" echo ${a/$~beg(#mi)1/-}
>> -234
>>  # a="1234"; beg="#"; num=1; echo ${a/$~beg(#mi)$~num/-}
>> zsh: bad pattern: #(#mi)1
>>  # a="1234"; beg="#" echo ${a/$~beg(#mi)1/-}
>> zsh: bad pattern: #(#mi)1
>>  #
>
> The difference is the first one doesn't have $beg defined at the point
> where the expansion takes place, because beg is being put into the
> environment to use when the command is run.  The environment of the
> command is not the same thing as the set of variables avaiable to the
> shell for preparing the command line.
>
> So what you're executing that works is actually
>
> a="1234"
> echo ${a/(#mi)1/-}
>
> After that, the result is self explanatory --- #(#mi) is a bad pattern
> (with EXTENDED_GLOB set).
>
> pws



Messages sorted by: Reverse Date, Date, Thread, Author