(autoconf.info)Portable Shell


Next: Portable Make Prev: Writing Autoconf Macros Up: Top

10 Portable Shell Programming
*****************************

When writing your own checks, there are some shell-script programming
techniques you should avoid in order to make your code portable.  The
Bourne shell and upward-compatible shells like the Korn shell and Bash
have evolved over the years, but to prevent trouble, do not take
advantage of features that were added after Unix version 7, circa 1977
(Note: Systemology).

   You should not use aliases, negated character classes, or other
features that are not found in all Bourne-compatible shells; restrict
yourself to the lowest common denominator.  Even `unset' is not
supported by all shells!

   Shell functions are considered portable nowadays, though Autoconf
still 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
`#!' line; for instance, 32 bytes (not including the newline) on SunOS
4.  A few ancient 4.2BSD based systems (such as Dynix circa 1984)
required a single space between the `#!' and the `/'.  However, these
ancient systems are no longer of practical concern.

   The set of external programs you should run in a `configure' script
is fairly small.  Note: Utilities in Makefiles
Makefiles, for the list.  This restriction allows users to start out
with a fairly small set of programs and build the rest, avoiding too
many interdependencies between packages.

   Some of these external utilities have a portable subset of features;
see Note: Limitations of Usual Tools.

   There are other sources of documentation about shells.  The
specification for the Posix Shell Command Language
(http://www.opengroup.org/susv3/utilities/xcu_chap02.html), though more
generous than the restrictive shell subset described above, is fairly
portable nowadays.  Also please see the Shell FAQs
(http://www.faqs.org/faqs/unix-faq/shell/).

* Shellology
A zoology of shells
* Here-Documents
Quirks and tricks
* File Descriptors
FDs and redirections
* File System Conventions
File names
* Shell Pattern Matching
Pattern matching
* Shell Substitutions
Variable and command expansions
* Assignments
Varying side effects of assignments
* Parentheses
Parentheses in shell scripts
* Slashes
Slashes in shell scripts
* Special Shell Variables
Variables you should not change
* Shell Functions
What to look out for if you use them
* Limitations of Builtins
Portable use of not so portable /bin/sh
* Limitations of Usual Tools
Portable use of portable tools

automatically generated by info2www