* bug with aliases and declaring functions
@ 2005-08-30 1:08 Pete Fritchman
2005-08-30 15:21 ` Bart Schaefer
0 siblings, 1 reply; 2+ messages in thread
From: Pete Fritchman @ 2005-08-30 1:08 UTC (permalink / raw)
To: zsh-workers
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: bug with aliases and declaring functions
2005-08-30 1:08 bug with aliases and declaring functions Pete Fritchman
@ 2005-08-30 15:21 ` Bart Schaefer
0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2005-08-30 15:21 UTC (permalink / raw)
To: Pete Fritchman, zsh-workers
On Aug 29, 6:08pm, Pete Fritchman wrote:
}
} 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.
Yes, that's what's happening, as is explained in zsh FAQ #2.3, except
that it's a mistake to call it "re-writing."
The discussion of aliasing in the zsh manual says "Every token in the
shell input is checked ..." -- note that it says token, indicating that
aliasing is applied after lexical analysis, and that it specifically
does not say anything about requiring spaces to surround the token.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-08-30 15:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-30 1:08 bug with aliases and declaring functions Pete Fritchman
2005-08-30 15:21 ` Bart Schaefer
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).