autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fix IRIX testsuite debugging failures: $0 in functions.


From: Ralf Wildenhues
Subject: Re: Fix IRIX testsuite debugging failures: $0 in functions.
Date: Tue, 20 Nov 2007 22:51:18 +0100
User-agent: Mutt/1.5.13 (2006-08-11)

Hello Eric,

* Eric Blake wrote on Tue, Nov 20, 2007 at 02:17:51AM CET:
> According to Ralf Wildenhues on 11/19/2007 1:26 PM:
> >     Do not use $0 inside a function, as IRIX sh will set that to the
> >     function name rather than the script invocation name.
> 
> Let's mention that in the manual.

Yes, I had a new chapter for shell functions in mind.  For now I've
applied the first patch below, to fix a trivial bug in my last patch.  

The second is what documentation changes I have for now, it needs a bit
more polish, and should probably avoid some of the duplication with
other chapters; but it still does not contain all function-related
issues (like FPATH).  Suggestions welcome.

If you agree with linking to Sven's pages, then I will ask him if he's
OK with it.  (I'm sure he won't mind, but asking can't hurt.)

Cheers,
Ralf

    * lib/autotest/general.m4 (AT_INIT) <at_func_create_debugging_script>:
    Fix quoting.

diff --git a/lib/autotest/general.m4 b/lib/autotest/general.m4
index 08f6e63..8b6a34a 100644
--- a/lib/autotest/general.m4
+++ b/lib/autotest/general.m4
@@ -331,7 +331,7 @@ at_func_create_debugging_script ()
     echo 'test "${ZSH_VERSION+set}" = set dnl
 && alias -g '\''${1+"address@hidden"}'\''='\''"address@hidden"'\'''
     AS_ECHO(["cd '$at_dir'"])
-    AS_ECHO(["exec \${CONFIG_SHELL-$SHELL} $at_myself -v -d ]dnl
+    AS_ECHO(["exec \${CONFIG_SHELL-$SHELL} \"$at_myself\" -v -d ]dnl
 [$at_debug_args $at_group \${1+\"address@hidden"}"])
     echo 'exit 1'
   } >$at_group_dir/run



    * doc/autoconf.texi (Shell Functions): New chapter.  Document
    IRIX sh $0 issue in functions, move content from ...
    (Portable Shell): ... here.
    (Shell Script Compiler): Note that shell functions are not
    totally unportable any more.

diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 7f3428a..26410c9 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -485,6 +485,7 @@ Portable Shell Programming
 * Parentheses::                 Parentheses in shell scripts
 * Slashes::                     Slashes in shell scripts
 * Special Shell Variables::     Variables you should not change
+* Shell Functions::             Shell Functions and Parameters
 * Limitations of Builtins::     Portable use of not so portable /bin/sh
 * Limitations of Usual Tools::  Portable use of portable tools
 
@@ -1040,6 +1041,8 @@ make it easy to write @command{configure} scripts by 
hand.  Sigh!
 Unfortunately, shell functions do not belong to the least common
 denominator; therefore, where you would like to define a function and
 use it ten times, you would instead need to copy its body ten times.
+Even in 2007, where shells without any function support are far and
+few between, there are pitfalls to avoid when making use of them.
 
 So, what is really needed is some kind of compiler, @command{autoconf},
 that takes an Autoconf program, @file{configure.ac}, and transforms it
@@ -12156,21 +12159,8 @@ to the lowest common denominator.  Even @code{unset} 
is not supported
 by all shells!
 
 Shell functions are considered portable nowadays, though Autoconf still
-does not use them (Autotest does).  However, 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 find a shell that
-does not exhibit the bug, zsh might be the only shell present on the
-user's machine.  Also, variables and functions may share a namespace,
-for example with Solaris 10 @command{/bin/sh}:
-
address@hidden
-$ @kbd{f () @{ :; @}; f=; f}
-f: not found
address@hidden example
-
address@hidden
-For this reason, Autotest uses the prefix @samp{at_func_} for its functions.
+does not use them (Autotest does).  However, some pitfalls have to be
+avoided for portable use of shell functions.
 
 Some ancient systems have quite
 small limits on the length of the @samp{#!} line; for instance, 32
@@ -12207,6 +12197,7 @@ subset described above, is fairly portable nowadays.  
Also please see
 * Parentheses::                 Parentheses in shell scripts
 * Slashes::                     Slashes in shell scripts
 * Special Shell Variables::     Variables you should not change
+* Shell Functions::             Shell Functions and Parameters
 * Limitations of Builtins::     Portable use of not so portable /bin/sh
 * Limitations of Usual Tools::  Portable use of portable tools
 @end menu
@@ -13525,6 +13516,46 @@ This variable is an alias to @samp{$?} for @code{zsh} 
(at least 3.1.6),
 hence read-only.  Do not use it.
 @end table
 
address@hidden Shell Functions
address@hidden Shell Functions
address@hidden Shell Functions
+
+Nowadays, it is difficult to find a shell that does not support
+shell functions at all.  However, some differences in support should
+be expected:
+
+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
address@hidden, as this triggers bugs in zsh 4.x; while Autoconf tries to
+find a shell that does not exhibit the bug, zsh might be the only shell
+present on the user's machine.
+
+Shell variables and functions may share a namespace, for example with
+Solaris 10 @command{/bin/sh}:
+
address@hidden
+$ @kbd{f () @{ :; @}; f=; f}
+f: not found
address@hidden example
+
address@hidden
+For this reason, Autotest uses the prefix @samp{at_func_} for its
+functions.
+
+Handling of positional parameters and shell options varies among shells.
+For example, Korn shells reset and restore trace output (@samp{set -x})
+and other options upon function entry and exit.  Inside a function,
+IRIX sh sets @samp{$0} to the function name.
+
+Some ancient Bourne shell variants with function support did not reset
address@hidden@var{i}, @var{i} >= 0}, upon function exit, so effectively the
+arguments of the script are lost after the first function invocation.
+It is probably not worth worrying about these shells any more.  More
+explanations about this issue can be found on
address@hidden://www.in-ulm.de/@/~mascheck/@/bourne/@/function_parameters.html,
+Sven Mascheck's page} about this issue.
+
+
 @node Limitations of Builtins
 @section Limitations of Shell Builtins
 @cindex Shell builtins




reply via email to

[Prev in Thread] Current Thread [Next in Thread]