[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/2] docs: mention ksh bug with function syntax
From: |
Eric Blake |
Subject: |
[PATCH 1/2] docs: mention ksh bug with function syntax |
Date: |
Tue, 3 Aug 2010 16:17:33 -0600 |
* doc/autoconf.texi (Shell Functions): Document ksh93 limitation.
Signed-off-by: Eric Blake <address@hidden>
---
I'm pushing both of these.
ChangeLog | 5 +++++
doc/autoconf.texi | 28 +++++++++++++++++++++-------
2 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 2cbd690..3d3ace6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-08-03 Eric Blake <address@hidden>
+
+ docs: mention ksh bug with function syntax
+ * doc/autoconf.texi (Shell Functions): Document ksh93 limitation.
+
2010-08-03 Ralf Wildenhues <address@hidden>
Fix typo in Autotest color test, for dash testsuite failure.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index df0e298..e292062 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -16202,6 +16202,20 @@ Shell Functions
Nowadays, it is difficult to find a shell that does not support
shell functions at all. However, some differences should be expected.
+When declaring a shell function, you must include whitespace between the
address@hidden)} after the function name and the start of the compound
+expression, to avoid upsetting @command{ksh}. While it is possible to
+use any compound command, most scripts use @address@hidden@address@hidden
+
address@hidden
+$ @kbd{/bin/sh -c 'a()@{ echo hi;@}; a'}
+hi
+$ @kbd{ksh -c 'a()@{ echo hi;@}; a'}
+ksh: syntax error at line 1: address@hidden' unexpected
+$ @kbd{ksh -c 'a() @{ echo hi;@}; a'}
+hi
address@hidden example
+
Inside a shell function, you should not rely on the error status of a
subshell if the last command of that subshell was @code{exit} or
@code{trap}, as this triggers bugs in zsh 4.x; while Autoconf tries to
@@ -16213,10 +16227,10 @@ Shell Functions
command in a @command{trap} handler can cause problems.
@example
-$ @kbd{bash -c 'foo()@{ echo $?; @}; trap foo 0; (exit 2); exit 2'; echo $?}
+$ @kbd{bash -c 'foo() @{ echo $?; @}; trap foo 0; (exit 2); exit 2'; echo $?}
2
2
-$ @kbd{ash -c 'foo()@{ echo $?; @}; trap foo 0; (exit 2); exit 2'; echo $?}
+$ @kbd{ash -c 'foo() @{ echo $?; @}; trap foo 0; (exit 2); exit 2'; echo $?}
0
2
@end example
@@ -16231,8 +16245,8 @@ Shell Functions
@samp{set -e}, for example with Solaris 10 @command{bin/sh}:
@example
-$ @kbd{bash -c 'f()@{ return 1; @}; set -e; f; echo oops}
-$ @kbd{/bin/sh -c 'f()@{ return 1; @}; set -e; f; echo oops}
+$ @kbd{bash -c 'f() @{ return 1; @}; set -e; f; echo oops}
+$ @kbd{/bin/sh -c 'f() @{ return 1; @}; set -e; f; echo oops}
oops
@end example
@@ -16259,13 +16273,13 @@ Shell Functions
affect the current environment in the same manner as special built-ins.
@example
-$ @kbd{/bin/sh -c 'func()@{ echo $a;@}; a=1 func; echo $a'}
+$ @kbd{/bin/sh -c 'func() @{ echo $a;@}; a=1 func; echo $a'}
@result{}
@result{}
-$ @kbd{ash -c 'func()@{ echo $a;@}; a=1 func; echo $a'}
+$ @kbd{ash -c 'func() @{ echo $a;@}; a=1 func; echo $a'}
@result{}1
@result{}
-$ @kbd{bash -c 'set -o posix; func()@{ echo $a;@}; a=1 func; echo $a'}
+$ @kbd{bash -c 'set -o posix; func() @{ echo $a;@}; a=1 func; echo $a'}
@result{}1
@result{}1
@end example
--
1.7.2
- [PATCH 1/2] docs: mention ksh bug with function syntax,
Eric Blake <=