From: Cuong Manh Le <cuong.manhle.vn@gmail.com>
To: "Ngô Huy" <huynhok.uit@vnoss.org>
Cc: Matthew Martin <phy1729@gmail.com>, Zsh Users <zsh-users@zsh.org>
Subject: Re: [Zsh bug] function define bug
Date: Wed, 25 Nov 2015 16:58:50 +0700 [thread overview]
Message-ID: <CALS7p_fynYn14Js5dLb9P74ac=ox1pMsBGhZsHZOYD0cDuZJ4w@mail.gmail.com> (raw)
In-Reply-To: <CAPO9ZdqXvxmO8ykzNGCs9Piov+pgHaJCchiF_BeQ+kD8z2yRCQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3208 bytes --]
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@vnoss.org> wrote:
> Dear Cuong,
>
> 2015-11-25 16:20 GMT+07:00 Cuong Manh Le <cuong.manhle.vn@gmail.com>:
>
>> 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@vnoss.org> wrote:
>>
>>> Dear Cuong,
>>>
>>> 2015-11-25 15:49 GMT+07:00 Cuong Manh Le <cuong.manhle.vn@gmail.com>:
>>>
>>>> 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@vnoss.org>
>>>> wrote:
>>>>
>>>>> Dear Matthew
>>>>>
>>>>> 2015-11-25 11:06 GMT+07:00 Matthew Martin <phy1729@gmail.com>:
>>>>>
>>>>> > On Tue, Nov 24, 2015 at 9:46 PM, Ngô Huy <huynhok.uit@vnoss.org>
>>>>> 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
>
next prev parent reply other threads:[~2015-11-25 10:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-25 3:46 Ngô Huy
2015-11-25 4:06 ` Matthew Martin
2015-11-25 4:20 ` Ngô Huy
2015-11-25 8:49 ` Cuong Manh Le
2015-11-25 9:03 ` Ngô Huy
2015-11-25 9:04 ` Ngô Huy
2015-11-25 9:16 ` Christoph (Stucki) von Stuckrad
2015-11-25 9:20 ` Cuong Manh Le
2015-11-25 9:39 ` Ngô Huy
2015-11-25 9:58 ` Cuong Manh Le [this message]
2015-11-25 10:00 ` Peter Stephenson
2015-11-25 10:13 ` Ngô Huy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CALS7p_fynYn14Js5dLb9P74ac=ox1pMsBGhZsHZOYD0cDuZJ4w@mail.gmail.com' \
--to=cuong.manhle.vn@gmail.com \
--cc=huynhok.uit@vnoss.org \
--cc=phy1729@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).