]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Document another awk pitfall.
authorEric Blake <ebb9@byu.net>
Thu, 13 Sep 2007 16:50:38 +0000 (16:50 +0000)
committerEric Blake <ebb9@byu.net>
Thu, 13 Sep 2007 16:50:38 +0000 (16:50 +0000)
* doc/autoconf.texi (Limitations of Usual Tools) <awk>: Document
limitation of field variables in END.
Reported by Gary V. Vaughan.

ChangeLog
doc/autoconf.texi

index c49031cd20d602caa246a03f60c4dd6d3d173955..d0ce0a6e93381ec5748ad964e87d22897f5c3e9d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2007-09-13  Eric Blake  <ebb9@byu.net>
 
+       Document another awk pitfall.
+       * doc/autoconf.texi (Limitations of Usual Tools) <awk>: Document
+       limitation of field variables in END.
+       Reported by Gary V. Vaughan.
+
        * AUTHORS: Add missing entries.
 
 2007-09-12  Eric Blake  <ebb9@byu.net>
index 52faf505256a8496d7dba3ab459fca99e62642d8..e5d2fee137ef0b1d5dad09faf60e3d96f2116aa5 100644 (file)
@@ -13361,6 +13361,23 @@ input in this case.  Portable scripts can redirect input from
 awk 'BEGIN @{print "hello world"@}' </dev/null
 @end example
 
+Posix says that in an @samp{END} action, @samp{$NF} (and presumably,
+@samp{$1}) retain their value from the last record read, if no
+intervening @samp{getline} occurred.  However, some implementations
+(such as Solaris 10 @samp{/usr/bin/awk}, @samp{nawk}, or Darwin
+@samp{awk}) reset these variables.  A workaround is to use an
+intermediate variable prior to the @samp{END} block.  For example:
+
+@example
+$ @kbd{cat end.awk}
+@{ tmp = $1 @}
+END @{ print "a", $1, $NF, "b", tmp @}
+$ @kbd{echo 1 | awk -f end.awk}
+a   b 1
+$ @kbd{echo 1 | gawk -f end.awk}
+a 1 1 b 1
+@end example
+
 If you want your program to be deterministic, don't depend on @code{for}
 on arrays: