[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: FYI: fix-bootstrap-translation-download-on-darwin
From: |
Eric Blake-1 |
Subject: |
Re: FYI: fix-bootstrap-translation-download-on-darwin |
Date: |
Wed, 12 Sep 2007 20:53:22 -0700 (PDT) |
> It appears that only gawk saves $3 from the last input line for use in
> the END clause, where darwin awk (maybe others too, I haven't looked
> elsewhere) discards it.
On Solaris 8, /usr/bin/awk and /usr/bin/nawk leave $3 empty,
while /usr/xpg4/bin/awk leaves it populated. POSIX states that
inside END, $NF must retain at the value it had for the last
record read (which would imply that $3 should do likewise),
but I saw nothing that actually required $3 remain populated.
At any rate, it is a definite portability pitfall, so how about the
following patch?
2007-09-12 Eric Blake <address@hidden>
Document another awk pitfall.
* doc/autoconf.texi (Limitations of Usual Tools) <awk>: Document
limitation of field variables in END.
Reported by Gary V. Vaughan.
Index: doc/autoconf.texi
===================================================================
RCS file: /sources/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.1174
diff -u -p -r1.1174 autoconf.texi
--- doc/autoconf.texi 13 Sep 2007 03:21:18 -0000 1.1174
+++ doc/autoconf.texi 13 Sep 2007 03:51:47 -0000
@@ -13361,6 +13361,23 @@ input in this case. Portable scripts ca
awk 'BEGIN @{print "hello world"@}' </dev/null
@end example
+Posix says that in an @samp{END} action, @samp{$NF} (and presumably,
address@hidden) 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
address@hidden) reset these variables. A workaround is to use an
+intermediate variable prior to the @samp{END} block. For example:
+
address@hidden
+$ @kbd{cat end.awk}
address@hidden 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
address@hidden example
+
If you want your program to be deterministic, don't depend on @code{for}
on arrays:
--
View this message in context:
http://www.nabble.com/Re%3A-FYI%3A-fix-bootstrap-translation-download-on-darwin-tf4432919.html#a12648290
Sent from the Gnu - Autoconf - General mailing list archive at Nabble.com.