pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/doc/guide/files Using printf is another way to print a...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/410901b89f64
branches:  trunk
changeset: 515246:410901b89f64
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Thu Jun 29 13:37:46 2006 +0000

description:
Using printf is another way to print an arbitrary string.

diffstat:

 doc/guide/files/makefile.xml |  18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)

diffs (46 lines):

diff -r 3605382bf738 -r 410901b89f64 doc/guide/files/makefile.xml
--- a/doc/guide/files/makefile.xml      Thu Jun 29 13:35:18 2006 +0000
+++ b/doc/guide/files/makefile.xml      Thu Jun 29 13:37:46 2006 +0000
@@ -1,11 +1,4 @@
-<!-- $NetBSD: makefile.xml,v 1.20 2006/05/15 16:28:19 reed Exp $ -->
-
-<!-- based on:
-pkgsrc/bootstrap/bmake/for.c 1.1.1.1
-pkgsrc/bootstrap/bmake/make.1 1.3
-pkgsrc/bootstrap/bmake/str.c 1.1.1.1
-pkgsrc/bootstrap/bmake/var.c 1.2
--->
+<!-- $NetBSD: makefile.xml,v 1.21 2006/06/29 13:37:46 rillig Exp $ -->
 
 <chapter id="makefile"> <?dbhtml filename="makefile.html"?>
   <title>Programming in <filename>Makefile</filename>s</title>
@@ -173,6 +166,10 @@
     <sect2 id="passing-variable-to-shell">
       <title>Passing variables to a shell command</title>
 
+       <para>Sometimes you may want to print an arbitrary string. There
+       are many ways to get it wrong and only few that can handle every
+       nastiness.</para>
+
 <programlisting>
     STRING=         foo bar <    > * `date` $$HOME ' "
     EXT_LIST=       string=${STRING:Q} x=second\ item
@@ -183,6 +180,7 @@
             echo "${STRING:Q}"              # 3
             echo ${STRING:Q}                # 4
             echo x${STRING:Q} | sed 1s,.,,  # 5
+            printf "%s\\n" ${STRING:Q}""    # 6
             env ${EXT_LIST} /bin/sh -c 'echo "$$string"; echo "$$x"'
 </programlisting>
 
@@ -207,6 +205,10 @@
       <para>Example 5 handles even the case of a leading dash
       correctly.</para>
 
+      <para>Example 6 also works with every string and is the
+      light-weight solution, since it does not involve a pipe, which has
+      its own problems.</para>
+
       <para>The <varname>EXT_LIST</varname> does not need to be quoted
       because the quoting has already been done when adding elements to
       the list.</para>



Home | Main Index | Thread Index | Old Index