autoconf: Portable Shell

1 
1 11 Portable Shell Programming
1 *****************************
1 
1 When writing your own checks, there are some shell-script programming
1 techniques you should avoid in order to make your code portable.  The
1 Bourne shell and upward-compatible shells like the Korn shell and Bash
1 have evolved over the years, and many features added to the original
1 System7 shell are now supported on all interesting porting targets.
1 However, the following discussion between Russ Allbery and Robert Lipe
1 is worth reading:
1 
1 Russ Allbery:
1 
1      The GNU assumption that `/bin/sh' is the one and only shell leads
1      to a permanent deadlock.  Vendors don't want to break users'
1      existing shell scripts, and there are some corner cases in the
1      Bourne shell that are not completely compatible with a Posix
1      shell.  Thus, vendors who have taken this route will _never_
1      (OK..."never say never") replace the Bourne shell (as `/bin/sh')
1      with a Posix shell.
1 
1 Robert Lipe:
1 
1      This is exactly the problem.  While most (at least most System
1      V's) do have a Bourne shell that accepts shell functions most
1      vendor `/bin/sh' programs are not the Posix shell.
1 
1      So while most modern systems do have a shell _somewhere_ that
1      meets the Posix standard, the challenge is to find it.
1 
11    For this reason, part of the job of M4sh (⇒Programming in
 M4sh) is to find such a shell.  But to prevent trouble, if you're not
1 using M4sh you should not take advantage of features that were added
1 after Unix version 7, circa 1977 (⇒Systemology); you should not
1 use aliases, negated character classes, or even `unset'.  `#' comments,
1 while not in Unix version 7, were retrofitted in the original Bourne
1 shell and can be assumed to be part of the least common denominator.
1 
1    On the other hand, if you're using M4sh you can assume that the shell
1 has the features that were added in SVR2 (circa 1984), including shell
1 functions, `return', `unset', and I/O redirection for builtins.  For
1 more information, refer to `http://www.in-ulm.de/~mascheck/bourne/'.
1 However, some pitfalls have to be avoided for portable use of these
1 constructs; these will be documented in the rest of this chapter.  See
DONTPRINTYET 1 in particular ⇒Shell Functions and *noteLimitations of Shell
1DONTPRINTYET 1 in particular ⇒Shell Functions and ⇒Limitations of Shell

 Builtins Limitations of Builtins.
1 
1    Some ancient systems have quite small limits on the length of the
1 `#!' line; for instance, 32 bytes (not including the newline) on SunOS
1 4.  However, these ancient systems are no longer of practical concern.
1 
1    The set of external programs you should run in a `configure' script
11 is fairly small.  ⇒Utilities in Makefiles (standards)Utilities in
 Makefiles, for the list.  This restriction allows users to start out
1 with a fairly small set of programs and build the rest, avoiding too
1 many interdependencies between packages.
1 
1    Some of these external utilities have a portable subset of features;
1 see ⇒Limitations of Usual Tools.
1 
1    There are other sources of documentation about shells.  The
1 specification for the Posix Shell Command Language
1 (http://www.opengroup.org/susv3/utilities/xcu_chap02.html), though more
1 generous than the restrictive shell subset described above, is fairly
1 portable nowadays.  Also please see the Shell FAQs
1 (http://www.faqs.org/faqs/unix-faq/shell/).
1 

Menu