* POSIX woes in t7810.87: dash bash or bash dash?
@ 2011-06-20 9:58 Michael J Gruber
2011-06-20 11:04 ` Jonathan Nieder
2011-06-20 21:46 ` Junio C Hamano
0 siblings, 2 replies; 7+ messages in thread
From: Michael J Gruber @ 2011-06-20 9:58 UTC (permalink / raw)
To: Git Mailing List
GNU bash, Version 4.2.10(1)-release (x86_64-redhat-linux-gnu):
echo "a\"b\n\"c"
a"b\n"c
dash-0.5.6:
echo "a\"b\n\"c"
a"b
"c
t7810.87 breaks with dash because of this. Escaping the \n does not make
the test work with both either. So I'd like to know which one's right
and (independently) how to make it work for both...
Cheers,
Michael
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: POSIX woes in t7810.87: dash bash or bash dash?
2011-06-20 9:58 POSIX woes in t7810.87: dash bash or bash dash? Michael J Gruber
@ 2011-06-20 11:04 ` Jonathan Nieder
2011-06-20 17:13 ` Jeff King
2011-06-20 21:46 ` Junio C Hamano
1 sibling, 1 reply; 7+ messages in thread
From: Jonathan Nieder @ 2011-06-20 11:04 UTC (permalink / raw)
To: Michael J Gruber; +Cc: Git Mailing List
Hi Michael,
Michael J Gruber wrote:
> echo "a\"b\n\"c"
> a"b
> "c
>
> t7810.87 breaks with dash because of this. Escaping the \n does not make
> the test work with both either.
This seems to have slipped by because testing it requires USE_LIBPCRE
to be set. Thanks for catching it.
> So I'd like to know which one's right
> and (independently) how to make it work for both...
Both are right. The simplest fix is to use printf, as in
printf "%s\n" "a\"b\n\"c"
See [1] and [2].
Regards,
Jonathan
[1] http://www.gnu.org/s/hello/manual/autoconf/Limitations-of-Builtins.html#echo
[2] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: POSIX woes in t7810.87: dash bash or bash dash?
2011-06-20 11:04 ` Jonathan Nieder
@ 2011-06-20 17:13 ` Jeff King
0 siblings, 0 replies; 7+ messages in thread
From: Jeff King @ 2011-06-20 17:13 UTC (permalink / raw)
To: Jonathan Nieder; +Cc: Michael J Gruber, Git Mailing List
On Mon, Jun 20, 2011 at 06:04:41AM -0500, Jonathan Nieder wrote:
> Michael J Gruber wrote:
>
> > echo "a\"b\n\"c"
> > a"b
> > "c
> >
> > t7810.87 breaks with dash because of this. Escaping the \n does not make
> > the test work with both either.
>
> This seems to have slipped by because testing it requires USE_LIBPCRE
> to be set. Thanks for catching it.
Yeah, I test with dash, too, and missed it because I hadn't enabled
pcre.
> > So I'd like to know which one's right
> > and (independently) how to make it work for both...
>
> Both are right. The simplest fix is to use printf, as in
>
> printf "%s\n" "a\"b\n\"c"
>
> See [1] and [2].
Yep. We've dealt with this before and used printf as the solution. E.g.:
938791c (git-rebase--interactive.sh: use printf instead of echo to print commit message, 2010-07-22)
4d2e283 (git-am: re-fix the diag message printing, 2009-01-18)
a23bfae (More echo "$user_message" fixes., 2007-05-26)
4b7cc26 (git-am: use printf instead of echo on user-supplied strings, 2007-05-25)
-Peff
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: POSIX woes in t7810.87: dash bash or bash dash?
2011-06-20 9:58 POSIX woes in t7810.87: dash bash or bash dash? Michael J Gruber
2011-06-20 11:04 ` Jonathan Nieder
@ 2011-06-20 21:46 ` Junio C Hamano
2011-06-20 23:24 ` Jeff King
1 sibling, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2011-06-20 21:46 UTC (permalink / raw)
To: Michael J Gruber; +Cc: Git Mailing List
Thanks for noticing. Let's do this.
t/t7810-grep.sh | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index 69bd576..6379ad6 100755
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
@@ -658,9 +658,9 @@ test_expect_success LIBPCRE 'grep -P -v pattern' '
'
test_expect_success LIBPCRE 'grep -P -i pattern' '
- {
- echo "hello.c: printf(\"Hello world.\n\");"
- } >expected &&
+ cat >expected <<-EOF &&
+ hello.c: printf("Hello world.\n");
+ EOF
git grep -P -i "PRINTF\([^\d]+\)" hello.c >actual &&
test_cmp expected actual
'
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: POSIX woes in t7810.87: dash bash or bash dash?
2011-06-20 21:46 ` Junio C Hamano
@ 2011-06-20 23:24 ` Jeff King
2011-06-20 23:31 ` Junio C Hamano
0 siblings, 1 reply; 7+ messages in thread
From: Jeff King @ 2011-06-20 23:24 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Michael J Gruber, Git Mailing List
On Mon, Jun 20, 2011 at 02:46:08PM -0700, Junio C Hamano wrote:
> diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
> index 69bd576..6379ad6 100755
> --- a/t/t7810-grep.sh
> +++ b/t/t7810-grep.sh
> @@ -658,9 +658,9 @@ test_expect_success LIBPCRE 'grep -P -v pattern' '
> '
>
> test_expect_success LIBPCRE 'grep -P -i pattern' '
> - {
> - echo "hello.c: printf(\"Hello world.\n\");"
> - } >expected &&
> + cat >expected <<-EOF &&
> + hello.c: printf("Hello world.\n");
> + EOF
Do you need to quote EOF to suppress expansion in the here document?
Both bash and dash seem to pass unknown backslash-escapes like "\n"
through unharmed, but I don't know if that is portable (they do both
munge known escapes like "\\", of course).
-Peff
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: POSIX woes in t7810.87: dash bash or bash dash?
2011-06-20 23:24 ` Jeff King
@ 2011-06-20 23:31 ` Junio C Hamano
2011-06-21 0:21 ` Jeff King
0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2011-06-20 23:31 UTC (permalink / raw)
To: Jeff King; +Cc: Michael J Gruber, Git Mailing List
Jeff King <peff@peff.net> writes:
> On Mon, Jun 20, 2011 at 02:46:08PM -0700, Junio C Hamano wrote:
>
>> diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
>> index 69bd576..6379ad6 100755
>> --- a/t/t7810-grep.sh
>> +++ b/t/t7810-grep.sh
>> @@ -658,9 +658,9 @@ test_expect_success LIBPCRE 'grep -P -v pattern' '
>> '
>>
>> test_expect_success LIBPCRE 'grep -P -i pattern' '
>> - {
>> - echo "hello.c: printf(\"Hello world.\n\");"
>> - } >expected &&
>> + cat >expected <<-EOF &&
>> + hello.c: printf("Hello world.\n");
>> + EOF
>
> Do you need to quote EOF to suppress expansion in the here document?
> Both bash and dash seem to pass unknown backslash-escapes like "\n"
> through unharmed, but I don't know if that is portable (they do both
> munge known escapes like "\\", of course).
I do not think that is strictly necessary, as we are not in the corner of
non-portable echo behaviour anymore, but I guess it wouldn't hurt.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: POSIX woes in t7810.87: dash bash or bash dash?
2011-06-20 23:31 ` Junio C Hamano
@ 2011-06-21 0:21 ` Jeff King
0 siblings, 0 replies; 7+ messages in thread
From: Jeff King @ 2011-06-21 0:21 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Michael J Gruber, Git Mailing List
On Mon, Jun 20, 2011 at 04:31:32PM -0700, Junio C Hamano wrote:
> >> + cat >expected <<-EOF &&
> >> + hello.c: printf("Hello world.\n");
> >> + EOF
> >
> > Do you need to quote EOF to suppress expansion in the here document?
> > Both bash and dash seem to pass unknown backslash-escapes like "\n"
> > through unharmed, but I don't know if that is portable (they do both
> > munge known escapes like "\\", of course).
>
> I do not think that is strictly necessary, as we are not in the corner of
> non-portable echo behaviour anymore, but I guess it wouldn't hurt.
I think my brain is fried from using too many almost-shell-compatible
quoting languages. For example, unknown escape sequences in C get their
backslash removed and the sequence used literally (at least by gcc; I
couldn't find anything definite in C99 on this).
But actually, POSIX is quite clear that a backslash before anything
besides:
$ ` " \ <newline>
is just a backslash, and gets included literally.
-Peff
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-06-21 0:21 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-20 9:58 POSIX woes in t7810.87: dash bash or bash dash? Michael J Gruber
2011-06-20 11:04 ` Jonathan Nieder
2011-06-20 17:13 ` Jeff King
2011-06-20 21:46 ` Junio C Hamano
2011-06-20 23:24 ` Jeff King
2011-06-20 23:31 ` Junio C Hamano
2011-06-21 0:21 ` Jeff King
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).