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

bug with aliases and declaring functions



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



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