[Top][All Lists]

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

Re: [PATCH] tests: don't silently skip the sort-version tests

From: Eric Blake
Subject: Re: [PATCH] tests: don't silently skip the sort-version tests
Date: Wed, 13 Jan 2010 06:10:55 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20090812 Thunderbird/ Mnenhy/

According to Jim Meyering on 1/13/2010 2:26 AM:
> The behavior of bash via /bin/sh (same for zsh and dash, though without
> the warning) is probably POSIX-conforming, but this example illustrates
> why it would be better to emulate openBSD's /bin/sh.
> * tests/misc/sort-version: Don't use <<- and indented here-doc contents.
> s/<<-/<</ and unindent the here-document contents.  Otherwise,
> bash would ignore the indented delimiter and use EOF, thus silently
> skipping this test.

Actually, this was a regression caused by your conversion from space to
tab indentation.  POSIX states: "If the redirection symbol is "<<-" , all
leading <tab> characters shall be stripped from input lines and the line
containing the trailing delimiter."  So it is only _required_ to work with
tabs; using spaces gives arbitrary results.

>  OpenBSD5.4's shell reported the failure:
>   $ printf 'cat<<-x\n foo\n x\n'|sh
>   sh: <stdin>[4]: here document `x' unclosed
>   [Exit 1]
> by contrast, bash warns but still exits successfully:
>   $ printf 'cat<<-x\n foo\n x\n'|bash && echo you lose
>   bash: line 3: warning: here-document at line 1 delimited by \
>     end-of-file (wanted `x')
>    foo
>    x
>   you lose

As proof, bash behaves just fine when you obey POSIX:

$ printf 'cat <<-x\n\thi\n\tx\n'|bash && echo you lose

We should mention this in the autoconf manual, so I'm pushing this.  I'm
not (yet) sure whether the warning about unterminated here-doc was
introduced in bash 4.0 or bash 4.1, but I can also confirm that bash 3.2
is silent whereas bash 4.1 warns (but the warning is longer than 80
columns, so it is not a nice fit in the manual).

Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
From f4fc1ad9bbd765a84dd6033e03541ffde9c7c045 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Wed, 13 Jan 2010 06:03:07 -0700
Subject: [PATCH] Document here-doc pitfall.

* doc/autoconf.texi (Here-Documents): Mention problem with <<-
Reported by Jim Meyering.

Signed-off-by: Eric Blake <address@hidden>
 ChangeLog         |    7 +++++++
 doc/autoconf.texi |   16 ++++++++++++++++
 2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6b6fd80..3fa0c5d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-01-13  Eric Blake  <address@hidden>
+       Document here-doc pitfall.
+       * doc/autoconf.texi (Here-Documents): Mention problem with <<-
+       operator.
+       Reported by Jim Meyering.
 2010-01-12  Eric Blake  <address@hidden>

        Typo fix in earlier commit.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index ce6ac88..31550fd 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -14691,6 +14691,22 @@ Here-Documents
 condition turned out to be false at runtime, and we end up not
 executing the macro at all.

+Be careful with the use of @samp{<<-} to unindent here-documents.  The
+behavior is only portable for stripping leading @key{TAB}s, and things
+can silently break if an overzealous editor converts to using leading
+spaces (not all shells are nice enough to warn about unterminated
+$ @kbd{printf 'cat <<-x\n\t1\n\t 2\n\tx\n' | bash && echo oops}
+ 2
+$ @kbd{printf 'cat <<-x\n 1\n  2\n x\n' | bash-3.2 && echo oops}
+ 1
+  2
+ x
address@hidden example
 @node File Descriptors
 @section File Descriptors
 @cindex Descriptors

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

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