Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: document more alias problems
- X-seq: zsh-workers 28377
- From: Peter Stephenson <Peter.Stephenson@xxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: document more alias problems
- Date: Wed, 27 Oct 2010 13:49:00 +0100
- In-reply-to: <87k4l34yfb.fsf@xxxxxxxxx>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- Organization: Cambridge Silicon Radio
- References: <4BF51CF3.8010609@xxxxxx> <4CC7EB88.8020105@xxxxxx> <20101027110240.16941d1f@xxxxxxxxxxxxxxxxxxxxxxxxx> <4CC801C1.1020109@xxxxxx> <20101027114840.2e586852@xxxxxxxxxxxxxxxxxxxxxxxxx> <87k4l34yfb.fsf@xxxxxxxxx>
While I'm at it, it's probably high time that another note on alias
problems was promoted to the manual. It's been in the FAQ for a while
but it could do with highlighting since it's really annoying and
confusing if you come across it.
Index: Doc/Zsh/grammar.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/grammar.yo,v
retrieving revision 1.20
diff -p -u -r1.20 grammar.yo
--- Doc/Zsh/grammar.yo 27 Oct 2010 12:29:13 -0000 1.20
+++ Doc/Zsh/grammar.yo 27 Oct 2010 12:45:19 -0000
@@ -500,6 +500,27 @@ is too late to expand the newly defined
a problem in shell scripts, functions, and code executed with `tt(source)'
or `tt(.)'. Consequently, use of functions rather than aliases is
recommended in non-interactive code.
+
+Note also the unhelpful interaction of aliases and function definitions:
+
+example(alias func='noglob func'
+func+LPAR()RPAR() {
+ echo Do something with $*
+})
+
+Because aliases are expanded in function definitions, this causes the
+following command to be executed:
+
+example(noglob func+LPAR()RPAR() {
+ echo Do something with $*
+})
+
+which defines tt(noglob) as well as tt(func) as functions with the
+body given. To avoid this, either quote the name tt(func) or use the
+alternative function definition form `tt(function func)'. Ensuring the
+alias is defined after the function works but is problematic if the
+code fragment might be re-executed.
+
texinode(Quoting)()(Aliasing)(Shell Grammar)
sect(Quoting)
cindex(quoting)
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK
Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
Messages sorted by:
Reverse Date,
Date,
Thread,
Author