From f4c37a78b150005b59801b0a2fdbb36b50a293be Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 21 Aug 2015 16:55:10 +0100 Subject: 36265 plus FAQ: fix alias expansion after "function" Owing to interesting historical parsing, names after the first were treated as command words so had non-global aliases expanded. Add an FAQ note that use of the function keyword works around other alias problems --- Etc/FAQ.yo | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'Etc/FAQ.yo') diff --git a/Etc/FAQ.yo b/Etc/FAQ.yo index 25a837ee7..9b7e558a6 100644 --- a/Etc/FAQ.yo +++ b/Etc/FAQ.yo @@ -778,6 +778,27 @@ label(23) mytt(function) to define a function, which doesn't expand aliases. It is possible to argue for extra warnings somewhere in this mess. + One workaround for this is to use the "function" keyword instead: + verb( + alias l='/bin/ls -F' + function l { /bin/ls -la "$@" | more } + ) + The mytt(l) after mytt(function) is not expanded. Note you don't need + the mytt(LPAR()RPAR()) in this case, although it's harmless. + + You need to be careful if you are defining a function with multiple + names; most people don't need to do this, so it's an unusual problem, + but in case you do you should be aware that in versions of the shell + before 5.1 names after the first em(were) expanded: + verb( + function a b c { ... } + ) + Here, mytt(b) and mytt(c), but not mytt(a), have aliases expanded. + This oddity was fixed in version 5.1. + + The rest of this item assumes you use the (more common, + but equivalent) mytt(LPAR()RPAR()) definitions. + Bart Schaefer's rule is: Define first those aliases you expect to use in the body of a function, but define the function first if the alias has the same name as the function. -- cgit 1.4.1