diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2018-07-31 09:21:43 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2018-07-31 09:21:43 +0300 |
commit | 86b063b99d78df97fcd761073f437ce00b018712 (patch) | |
tree | 6f834ea3d46ecb541bd6a722e565a83aac0e2268 /doc/gawktexi.in | |
parent | f856979d85ace61bfeb2d31146485ec668202ad8 (diff) | |
download | egawk-86b063b99d78df97fcd761073f437ce00b018712.tar.gz egawk-86b063b99d78df97fcd761073f437ce00b018712.tar.bz2 egawk-86b063b99d78df97fcd761073f437ce00b018712.zip |
Fix handling of physical newlines in -v arguments and related improvemnts.
Diffstat (limited to 'doc/gawktexi.in')
-rw-r--r-- | doc/gawktexi.in | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/doc/gawktexi.in b/doc/gawktexi.in index 2a2fdd4b..3ba511ba 100644 --- a/doc/gawktexi.in +++ b/doc/gawktexi.in @@ -10511,6 +10511,69 @@ eight-bit ASCII characters, including ASCII @sc{nul} (character code zero). Other @command{awk} implementations may have difficulty with some character codes. +Some languages allow you to continue long strings across +multiple lines by ending the line with a backslash. For example in C: + +@example +#include <stdio.h> + +int main() +@{ + printf "hello, \ +world\n"); + return 0; +@} +@end example + +@noindent +In such a case, the C compiler removes both the backslash and the newline, +producing a string as if it had been typed @samp{"hello, world\n"}. +This is useful when a single string needs to contain a large amount of text. + +The POSIX standard says explicitly that newlines are not allowed inside string +constants. And indeed, all @command{awk} implementations report an error +if you try to do so. For example: + +@example +$ @kbd{gawk 'BEGIN @{ print "hello, } +> @kbd{world" @}'} +@print{} gawk: cmd. line:1: BEGIN { print "hello, +@print{} gawk: cmd. line:1: ^ unterminated string +@print{} gawk: cmd. line:1: BEGIN { print "hello, +@print{} gawk: cmd. line:1: ^ syntax error +@end example + +@cindex dark corner, string continuation +@cindex strings, continuation across lines +@cindex differences in @command{awk} and @command{gawk}, strings +Although POSIX doesn't define what happens if you use an escaped +newline, as in the previous C example, all known versions of +@command{awk} allow you to do so. Unfortunately, what each one +does with such a string varies. @value{DARKCORNER} @command{gawk}, +@command{mawk}, and the OpenSolaris POSIX @command{awk} +(@pxref{Other Versions}) elide the backslash and newline, as in C: + +@example +$ @kbd{gawk 'BEGIN @{ print "hello, \} +> @kbd{world" @}'} +@print{} hello, world +@end example + +Brian Kernighan's @command{awk} and Busybox @command{awk} +remove the backslash but leave the newline +intact, as part of the string: + +@example +$ @kbd{nawk 'BEGIN @{ print "hello, \} +> @kbd{world" @}'} +@print{} hello, +@print{} world +@end example + +In POSIX mode (@pxref{Options}), @command{gawk} does not +allow escaped newlines. Otherwise, it behaves as +just described. + @node Nondecimal-numbers @subsubsection Octal and Hexadecimal Numbers @cindex octal numbers |