Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [Zsh bug] function define bug
- X-seq: zsh-users 20991
- From: Cuong Manh Le <cuong.manhle.vn@xxxxxxxxx>
- To: Ngô Huy <huynhok.uit@xxxxxxxxx>
- Subject: Re: [Zsh bug] function define bug
- Date: Wed, 25 Nov 2015 16:58:50 +0700
- Cc: Matthew Martin <phy1729@xxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=N3meTd8U9ZKtILY5np9CNrqsEVeQgjAL7ObPqm5Okic=; b=Kv33rBK1NHagVG1v82FEVJYrelqWFlshp+swoooTyQQUg9EczoGPZbjZDzNhHcZy5/ GFBbznmDpHM27Y66D/jurmgC6SvlFEPnSbOAK+8Sb4eaz0BxWQXgQ8NnVglbbkGAxM8Y FCzsbPkZ0a+Z8N2yyacTYL1prFKzQBIRlaLiC73T9bKk4lPKzXn2/wIkgGnCzlSkHKbd UWOvC5FlpIqV6PZodwHvLir95f5XApyF4iN3WCNU0qeZP2+zUgJuDUOn6T1HynpR78eY 82e61Jqw9tIN8iQzCvNbcmKp/lPt9rQK3U1lFU4mO+gYe1eUOcjFiv1tDs4eNqbEpA5M VM+A==
- In-reply-to: <CAPO9ZdqXvxmO8ykzNGCs9Piov+pgHaJCchiF_BeQ+kD8z2yRCQ@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAPO9ZdrRL9e+B4urS4S5EitsOqjQYYji6F13JWkmOwLA=FyEbw@mail.gmail.com> <CAGnh9tB8oEua8npLmkhbPPBvMq1C3wfusnTo0MzLx0RjAiGaHw@mail.gmail.com> <CAPO9Zdp4eHtM3n0GrP0TE2b9-u=6eWXYzrZg6w4BtbTL7644zA@mail.gmail.com> <CALS7p_cNO6=ZVnU9Zw_4exY+DWZxjEXQ=SOwU3O2fwDmq7Jmfg@mail.gmail.com> <CAPO9ZdrV2HORspz=H+rN=A5uT0w=3CbxQpB0PrKxXLWGgPg4XA@mail.gmail.com> <CALS7p_eigQakWkp0ryELD=7kUiGCzyRbbi6iq1NhChjANGRqVw@mail.gmail.com> <CAPO9ZdqXvxmO8ykzNGCs9Piov+pgHaJCchiF_BeQ+kD8z2yRCQ@mail.gmail.com>
Hi Huy,
See this commit
https://github.com/zsh-users/zsh/commit/b4a198cdda3d499af4e2b4f4a2279f98c8d07433
for an example usage.
Best.
On Wed, Nov 25, 2015 at 4:39 PM, Ngô Huy <huynhok.uit@xxxxxxxxx> wrote:
> Dear Cuong,
>
> 2015-11-25 16:20 GMT+07:00 Cuong Manh Le <cuong.manhle.vn@xxxxxxxxx>:
>
>> Hi Huy,
>>
>> It's a good point, but in the user perspective, turn off `multifuncdef`
>> is not much useful:
>>
>> $ unsetopt multifuncdef
>> $ echo 1 | grep foobar(){ echo 1; }
>> zsh: parse error near `()'
>>
>> You still stuck and can not use `grep`.
>>
>> The right way to use it from the beginning is quote the grep string
>> pattern if it contains any shell meta characters.
>>
>> Also in zsh documentation
>> http://zsh.sourceforge.net/Doc/Release/Options.html#index-MULTIFUNCDEF ,
>> it said that:
>>
>> Multiple function definitions are not often used and can cause obscure
>>> errors.
>>
>>
>> Maybe we should add an example to that section.
>>
>> Best.
>>
>>
>>
>> On Wed, Nov 25, 2015 at 4:03 PM, Ngô Huy <huynhok.uit@xxxxxxxxx> wrote:
>>
>>> Dear Cuong,
>>>
>>> 2015-11-25 15:49 GMT+07:00 Cuong Manh Le <cuong.manhle.vn@xxxxxxxxx>:
>>>
>>>> Hi Severus,
>>>>
>>>> Can you give a demo?
>>>>
>>>> You can turn off `multì_func_def` but you can always do multiple
>>>> function definition with reserved word `function`
>>>>
>>>> Best.
>>>>
>>>>
>>>> On Wed, Nov 25, 2015 at 11:20 AM, Ngô Huy <huynhok.uit@xxxxxxxxx>
>>>> wrote:
>>>>
>>>>> Dear Matthew
>>>>>
>>>>> 2015-11-25 11:06 GMT+07:00 Matthew Martin <phy1729@xxxxxxxxx>:
>>>>>
>>>>> > On Tue, Nov 24, 2015 at 9:46 PM, Ngô Huy <huynhok.uit@xxxxxxxxx>
>>>>> wrote:
>>>>> > > Dear folks,
>>>>> > >
>>>>> > > I found the problem in zsh define function. Demo
>>>>> > >
>>>>> > > ls test() { echo "Bug !!!"} && ls && test
>>>>> > >
>>>>> > > it will print
>>>>> > >
>>>>> > > Bug !!!
>>>>> > > Bug !!!
>>>>> >
>>>>> >
>>>>> > That's expected behaviour. Since MULTI_FUNC_DEF is set by default in
>>>>> zsh
>>>>> > mode, both ls and test are being defined as functions with the body
>>>>> > echo "Bug !!!".
>>>>> >
>>>>> > % func1 func2 () { echo This is "$0"; }
>>>>> > % func1; func2
>>>>> > This is func1
>>>>> > This is func2
>>>>> > % which func{1,2}
>>>>> > func1 () {
>>>>> > echo This is "$0"
>>>>> > }
>>>>> > func2 () {
>>>>> > echo This is "$0"
>>>>> > }
>>>>> > % unsetopt MULTI_FUNC_DEF
>>>>> > % func1 func2 () { echo This is "$0"; }
>>>>> > zsh: parse error near `()'
>>>>> >
>>>>>
>>>>> I know this behavior likes advanced programming language but
>>>>> multì_func_def
>>>>> should be turned off by default, it leads to risky problem when someone
>>>>> searchs as grep, ls malicious strings without quote
>>>>>
>>>>>
>>>>> Kind regards,
>>>>> Severus
>>>>>
>>>>
>>>> this's just example: cat file | grep foobar(){ rm -rf *}
>>> grep wil execute rest of body
>>>
>>> Kind regards,
>>> Severus
>>>
>>
>> I don't see any case we should use multiple function definition. We also
> can not cover all problems with this behavior. I think we should disable it
> :)
>
> Kind regards,
> Severus
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author