bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Suggestion on documentation about Dos quoting


From: Vincent Belaïche
Subject: Re: [bug-gawk] Suggestion on documentation about Dos quoting
Date: Wed, 26 Oct 2016 15:14:09 +0200

Just a little typo fixed in my previous contribution.

>Hello,
>
>Not a bug, just a suggestion about info node "(gawk) DOS Quoting".
>
>OK, this is out of scope of AWK, but let us be complete about the
>explanation or do nothing. Hopefully, my proposal is not too verbous.
>
>VBR,
>       Vincent.




---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel 
antivirus Avast.
https://www.avast.com/antivirus
diff --git a/doc/gawk.texi b/doc/gawk.texi
index e1b8fbb..03157fe 100644
--- a/doc/gawk.texi
+++ b/doc/gawk.texi
@@ -49,6 +49,14 @@
 @set MINUS
 @end ifdocbook
 
address@hidden
address@hidden TIMES @times
address@hidden iftex
address@hidden
address@hidden TIMES *
address@hidden ifnottex
+        
+
 @set xref-automatic-section-title
 
 @c The following information should be updated here only!
@@ -3017,14 +3025,55 @@ it is worth addressing.
 @cindex Brink, Jeroen
 The ``shells'' on Microsoft Windows systems use the double-quote
 character for quoting, and make it difficult or impossible to include an
-escaped double-quote character in a command-line script.
-The following example, courtesy of Jeroen Brink, shows
-how to print all lines in a file surrounded by double quotes:
-
+escaped double-quote character in a command-line script.  The following
+example, courtesy of Jeroen Brink, shows how to escape the double quotes
+from this one liner script that prints all lines in a file surrounded by
+double quotes:
address@hidden
address@hidden print "\"" $0 "\"" @}
address@hidden example
address@hidden
+In an MSDOS command-line the one-liner script above may be passed as
+follows:
 @example
 gawk "@{ print \"\042\" $0 \"\042\" @}" @var{file}
 @end example
 
+In this example the @code{\042} is the octal code for a double-quote as
+interpretable by the @code{print} function.
+
+In MSDOS escaping double-quotes is a little tricky because you use
+backslashes to escape double-quotes, but backslashes themselves are not
+escaped in the usual way, indeed they are either duplicated or not
+depending on whether there is a subsequent double-quote.  The MSDOS rule
+is the following to double-quote a string:
+
address@hidden
address@hidden
+For each double quote in the orginal string, let @var{N} be the number
+of backslash(es) before it, @var{N} might be 0, replace these @var{N}
+backslash(es) by @address@hidden@var{N}+1} backslash(es)
address@hidden
+Let @var{N} be the number of backslash(es) tailing the original string,
address@hidden might be @math{0}, then replace these @var{N} backslash(es) by
address@hidden@address@hidden backslash(es)
address@hidden
+Surround the resulting string by double-quotes.
address@hidden enumerate
+
+So to double-quote the one-liner script @address@hidden print "\"" $0 "\"" @}}
+from the previous example you would do it this way in the MSDOS command
+line:
+
address@hidden
+gawk "@{ print \"\\\"\" $0 \"\\\"\" @}" @var{file}
address@hidden example
+
address@hidden
+However, the use of @code{\042} instead of @code{\\\"} is also possible
+and easier to read, because backslashes that are not followed by a
+double-quote don't need duplication.
+
 
 @node Sample Data Files
 @section @value{DDF}s for the Examples

reply via email to

[Prev in Thread] Current Thread [Next in Thread]