{"thread":{"id":"27662","subject":"POSIX woes in t7810.87: dash bash or bash dash?","startedAt":"2011-06-20T09:58:28Z","lastAt":"2011-06-21T00:21:14Z","messageCount":7,"participants":["Michael J Gruber","Jonathan Nieder","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"170288","messageId":"4DFF19C4.5070003@drmicha.warpmail.net","threadId":"27662","inReplyTo":null,"subject":"POSIX woes in t7810.87: dash bash or bash dash?","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2011-06-20T09:58:28Z","receivedAt":"2011-06-20T09:58:28Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"GNU bash, Version 4.2.10(1)-release (x86_64-redhat-linux-gnu):\n\necho \"a\\\"b\\n\\\"c\"\na\"b\\n\"c\n\ndash-0.5.6:\n\necho \"a\\\"b\\n\\\"c\"\na\"b\n\"c\n\nt7810.87 breaks with dash because of this. Escaping the \\n does not make\nthe test work with both either. So I'd like to know which one's right\nand (independently) how to make it work for both...\n\nCheers,\nMichael\n"},{"id":"170291","messageId":"20110620110440.GA29270@elie","threadId":"27662","inReplyTo":"4DFF19C4.5070003@drmicha.warpmail.net","subject":"Re: POSIX woes in t7810.87: dash bash or bash dash?","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-06-20T11:04:41Z","receivedAt":"2011-06-20T11:04:41Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi Michael,\n\nMichael J Gruber wrote:\n\n> echo \"a\\\"b\\n\\\"c\"\n> a\"b\n> \"c\n>\n> t7810.87 breaks with dash because of this. Escaping the \\n does not make\n> the test work with both either.\n\nThis seems to have slipped by because testing it requires USE_LIBPCRE\nto be set.  Thanks for catching it.\n\n> So I'd like to know which one's right\n> and (independently) how to make it work for both...\n\nBoth are right.  The simplest fix is to use printf, as in\n\n\tprintf \"%s\\n\" \"a\\\"b\\n\\\"c\"\n\nSee [1] and [2].\n\nRegards,\nJonathan\n\n[1] http://www.gnu.org/s/hello/manual/autoconf/Limitations-of-Builtins.html#echo\n[2] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html\n"},{"id":"170309","messageId":"20110620171307.GA5859@sigill.intra.peff.net","threadId":"27662","inReplyTo":"20110620110440.GA29270@elie","subject":"Re: POSIX woes in t7810.87: dash bash or bash dash?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-06-20T17:13:07Z","receivedAt":"2011-06-20T17:13:07Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jun 20, 2011 at 06:04:41AM -0500, Jonathan Nieder wrote:\n\n> Michael J Gruber wrote:\n> \n> > echo \"a\\\"b\\n\\\"c\"\n> > a\"b\n> > \"c\n> >\n> > t7810.87 breaks with dash because of this. Escaping the \\n does not make\n> > the test work with both either.\n> \n> This seems to have slipped by because testing it requires USE_LIBPCRE\n> to be set.  Thanks for catching it.\n\nYeah, I test with dash, too, and missed it because I hadn't enabled\npcre.\n\n> > So I'd like to know which one's right\n> > and (independently) how to make it work for both...\n> \n> Both are right.  The simplest fix is to use printf, as in\n> \n> \tprintf \"%s\\n\" \"a\\\"b\\n\\\"c\"\n> \n> See [1] and [2].\n\nYep. We've dealt with this before and used printf as the solution. E.g.:\n\n  938791c (git-rebase--interactive.sh: use printf instead of echo to print commit message, 2010-07-22)\n  4d2e283 (git-am: re-fix the diag message printing, 2009-01-18)\n  a23bfae (More echo \"$user_message\" fixes., 2007-05-26)\n  4b7cc26 (git-am: use printf instead of echo on user-supplied strings, 2007-05-25)\n\n-Peff\n"},{"id":"170325","messageId":"7voc1sb2hr.fsf@alter.siamese.dyndns.org","threadId":"27662","inReplyTo":"4DFF19C4.5070003@drmicha.warpmail.net","subject":"Re: POSIX woes in t7810.87: dash bash or bash dash?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-06-20T21:46:08Z","receivedAt":"2011-06-20T21:46:08Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks for noticing. Let's do this.\n\n t/t7810-grep.sh |    6 +++---\n 1 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex 69bd576..6379ad6 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -658,9 +658,9 @@ test_expect_success LIBPCRE 'grep -P -v pattern' '\n '\n \n test_expect_success LIBPCRE 'grep -P -i pattern' '\n-\t{\n-\t\techo \"hello.c:\tprintf(\\\"Hello world.\\n\\\");\"\n-\t} >expected &&\n+\tcat >expected <<-EOF &&\n+\thello.c:\tprintf(\"Hello world.\\n\");\n+\tEOF\n \tgit grep -P -i \"PRINTF\\([^\\d]+\\)\" hello.c >actual &&\n \ttest_cmp expected actual\n '\n"},{"id":"170337","messageId":"20110620232425.GA617@sigill.intra.peff.net","threadId":"27662","inReplyTo":"7voc1sb2hr.fsf@alter.siamese.dyndns.org","subject":"Re: POSIX woes in t7810.87: dash bash or bash dash?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-06-20T23:24:25Z","receivedAt":"2011-06-20T23:24:25Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jun 20, 2011 at 02:46:08PM -0700, Junio C Hamano wrote:\n\n> diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\n> index 69bd576..6379ad6 100755\n> --- a/t/t7810-grep.sh\n> +++ b/t/t7810-grep.sh\n> @@ -658,9 +658,9 @@ test_expect_success LIBPCRE 'grep -P -v pattern' '\n>  '\n>  \n>  test_expect_success LIBPCRE 'grep -P -i pattern' '\n> -\t{\n> -\t\techo \"hello.c:\tprintf(\\\"Hello world.\\n\\\");\"\n> -\t} >expected &&\n> +\tcat >expected <<-EOF &&\n> +\thello.c:\tprintf(\"Hello world.\\n\");\n> +\tEOF\n\nDo you need to quote EOF to suppress expansion in the here document?\nBoth bash and dash seem to pass unknown backslash-escapes like \"\\n\"\nthrough unharmed, but I don't know if that is portable (they do both\nmunge known escapes like \"\\\\\", of course).\n\n-Peff\n"},{"id":"170339","messageId":"7vwrgg9j1n.fsf@alter.siamese.dyndns.org","threadId":"27662","inReplyTo":"20110620232425.GA617@sigill.intra.peff.net","subject":"Re: POSIX woes in t7810.87: dash bash or bash dash?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-06-20T23:31:32Z","receivedAt":"2011-06-20T23:31:32Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Mon, Jun 20, 2011 at 02:46:08PM -0700, Junio C Hamano wrote:\n>\n>> diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\n>> index 69bd576..6379ad6 100755\n>> --- a/t/t7810-grep.sh\n>> +++ b/t/t7810-grep.sh\n>> @@ -658,9 +658,9 @@ test_expect_success LIBPCRE 'grep -P -v pattern' '\n>>  '\n>>  \n>>  test_expect_success LIBPCRE 'grep -P -i pattern' '\n>> -\t{\n>> -\t\techo \"hello.c:\tprintf(\\\"Hello world.\\n\\\");\"\n>> -\t} >expected &&\n>> +\tcat >expected <<-EOF &&\n>> +\thello.c:\tprintf(\"Hello world.\\n\");\n>> +\tEOF\n>\n> Do you need to quote EOF to suppress expansion in the here document?\n> Both bash and dash seem to pass unknown backslash-escapes like \"\\n\"\n> through unharmed, but I don't know if that is portable (they do both\n> munge known escapes like \"\\\\\", of course).\n\nI do not think that is strictly necessary, as we are not in the corner of\nnon-portable echo behaviour anymore, but I guess it wouldn't hurt.\n"},{"id":"170342","messageId":"20110621002114.GA2050@sigill.intra.peff.net","threadId":"27662","inReplyTo":"7vwrgg9j1n.fsf@alter.siamese.dyndns.org","subject":"Re: POSIX woes in t7810.87: dash bash or bash dash?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-06-21T00:21:14Z","receivedAt":"2011-06-21T00:21:14Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jun 20, 2011 at 04:31:32PM -0700, Junio C Hamano wrote:\n\n> >> +\tcat >expected <<-EOF &&\n> >> +\thello.c:\tprintf(\"Hello world.\\n\");\n> >> +\tEOF\n> >\n> > Do you need to quote EOF to suppress expansion in the here document?\n> > Both bash and dash seem to pass unknown backslash-escapes like \"\\n\"\n> > through unharmed, but I don't know if that is portable (they do both\n> > munge known escapes like \"\\\\\", of course).\n> \n> I do not think that is strictly necessary, as we are not in the corner of\n> non-portable echo behaviour anymore, but I guess it wouldn't hurt.\n\nI think my brain is fried from using too many almost-shell-compatible\nquoting languages. For example, unknown escape sequences in C get their\nbackslash removed and the sequence used literally (at least by gcc; I\ncouldn't find anything definite in C99 on this).\n\nBut actually, POSIX is quite clear that a backslash before anything\nbesides:\n\n  $   `   \"   \\   <newline>\n\nis just a backslash, and gets included literally.\n\n-Peff\n"}]}