summaryrefslogtreecommitdiff
path: root/Etc/FAQ.yo
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2015-08-21 16:55:10 +0100
committerPeter Stephenson <pws@zsh.org>2015-08-21 16:55:10 +0100
commitf4c37a78b150005b59801b0a2fdbb36b50a293be (patch)
tree1adefe6b9a35852e38878979d6a66be698a6e851 /Etc/FAQ.yo
parentc0df3440a44ac74a09115b536019b8ca6076245f (diff)
downloadzsh-f4c37a78b150005b59801b0a2fdbb36b50a293be.tar.gz
zsh-f4c37a78b150005b59801b0a2fdbb36b50a293be.zip
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
Diffstat (limited to 'Etc/FAQ.yo')
-rw-r--r--Etc/FAQ.yo21
1 files changed, 21 insertions, 0 deletions
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.