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

Re: [Zsh bug] function define bug



Dear all,


2015-11-25 16:03 GMT+07:00 Ngô Huy <huynhok.uit@xxxxxxxxx>:

> 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 reason for multiple functions have same body but different
name. Let's me know if I'm wrong :)

Kind regards,
Severus


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