Node:Here-Documents, Next:, Previous:Shellology, Up:Portable Shell



Here-Documents

Don't rely on \ being preserved just because it has no special meaning together with the next symbol. in the native /bin/sh on OpenBSD 2.7 \" expands to " in here-documents with unquoted delimiter. As a general rule, if \\ expands to \ use \\ to get \.

With OpenBSD 2.7's /bin/sh

$ cat <<EOF
> \" \\
> EOF
" \

and with Bash:

bash-2.04$ cat <<EOF
> \" \\
> EOF
\" \

Many older shells (including the Bourne shell) implement here-documents inefficiently. Users can generally speed things up by using a faster shell, e.g., by using the command bash ./configure rather than plain ./configure.

Some shells can be extremely inefficient when there are a lot of here-documents inside a single statement. For instance if your configure.ac includes something like:

if <cross_compiling>; then
  assume this and that
else
  check this
  check that
  check something else
  ...
  on and on forever
  ...
fi

A shell parses the whole if/fi construct, creating temporary files for each here document in it. Some shells create links for such here-documents on every fork, so that the clean-up code they had installed correctly removes them. It is creating the links that the shell can take forever.

Moving the tests out of the if/fi, or creating multiple if/fi constructs, would improve the performance significantly. Anyway, this kind of construct is not exactly the typical use of Autoconf. In fact, it's even not recommended, because M4 macros can't look into shell conditionals, so we may fail to expand a macro when it was expanded before in a conditional path, and the condition turned out to be false at run-time, and we end up not executing the macro at all.