summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Etc/FAQ.yo21
-rw-r--r--Src/parse.c5
2 files changed, 24 insertions, 2 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.
diff --git a/Src/parse.c b/Src/parse.c
index 1a7416449..09317610b 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -1600,9 +1600,9 @@ par_funcdef(int *cmplx)
p = ecadd(0);
ecadd(0);
- incmdpos = 1;
while (tok == STRING) {
- if (*tokstr == Inbrace && !tokstr[1]) {
+ if ((*tokstr == Inbrace || *tokstr == '{') &&
+ !tokstr[1]) {
tok = INBRACE;
break;
}
@@ -1615,6 +1615,7 @@ par_funcdef(int *cmplx)
ecadd(0);
nocorrect = 0;
+ incmdpos = 1;
if (tok == INOUTPAR)
zshlex();
while (tok == SEPER)