zsh-workers
 help / color / mirror / code / Atom feed
From: Pete Fritchman <petef@databits.net>
To: zsh-workers@sunsite.dk
Subject: bug with aliases and declaring functions
Date: Mon, 29 Aug 2005 18:08:13 -0700	[thread overview]
Message-ID: <20050830010813.BEF5357B2D@hex.databits.net> (raw)

Hi,

$ alias foo='echo test|sort'
$ foo() { echo func; }
$ sort
func
$ 

If instead you declare the function with the function keyword, i.e.

function foo() { echo func; }

expected behavior occurs.  So, my theory is that the zsh parser is
re-writing 'foo() { echo func; }' to 'foo () { echo func; }' and then
'foo ' is seen at the beginning of the command, and foo's alias is
substituted.  This is also a useful test to see what's happening:

$ alias foo='echo test|sort'
$ set -x
$ foo() { echo func; }
+-/bin/zsh:5> echo test
$ foo () { echo func; }
+-/bin/zsh:6> echo test
$ set +x
$ declare -f
[...]
sort () {
        echo func
}
$

If this difference in behavior between 'foo() { ... }' and
'function foo() { ... }' is expected, I think it should be documented
somewhere.  Of course, I think this is a bug and should probably
be fixed :-)  BTW, as a data point: the same thing happens in bash.

thanks,
-- 
petef


             reply	other threads:[~2005-08-30  1:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-30  1:08 Pete Fritchman [this message]
2005-08-30 15:21 ` Bart Schaefer

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=20050830010813.BEF5357B2D@hex.databits.net \
    --to=petef@databits.net \
    --cc=zsh-workers@sunsite.dk \
    /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).