{"thread":{"id":"61500","subject":"[PATCH] t/t9902-completion.sh: backslashes in echo","startedAt":"2024-05-17T14:08:48Z","lastAt":"2024-05-23T23:21:44Z","messageCount":10,"participants":["Marcel Telka","Junio C Hamano","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"494972","messageId":"Zkdk7R9GIfsyQjkc@telcontar","threadId":"61500","inReplyTo":null,"subject":"[PATCH] t/t9902-completion.sh: backslashes in echo","fromName":"Marcel Telka","fromEmail":"marcel@telka.sk","sentAt":"2024-05-17T14:08:45Z","receivedAt":"2024-05-17T14:08:48Z","isPatch":true,"sender":{"key":"marcel@telka.sk","avatar":"https://avatars.githubusercontent.com/u/3000173?v=4"},"body":"The usage of backslashes in echo is not portable.  Since some tests\ntries to output strings containing '\\b' it is safer to use printf\nhere.  The usage of printf instead of echo is also preferred by POSIX.\n\nSigned-off-by: Marcel Telka <marcel@telka.sk>\n---\n t/t9902-completion.sh | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 963f865f27..ed3d03367e 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -73,7 +73,7 @@ _get_comp_words_by_ref ()\n print_comp ()\n {\n \tlocal IFS=$'\\n'\n-\techo \"${COMPREPLY[*]}\" > out\n+\tprintf '%s\\n' \"${COMPREPLY[*]}\" > out\n }\n \n run_completion ()\n"},{"id":"495440","messageId":"xmqqsey8tnny.fsf@gitster.g","threadId":"61500","inReplyTo":"Zkdk7R9GIfsyQjkc@telcontar","subject":"Re: [PATCH] t/t9902-completion.sh: backslashes in echo","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-05-23T17:59:13Z","receivedAt":"2024-05-23T17:59:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Marcel Telka <marcel@telka.sk> writes:\n\n> The usage of backslashes in echo is not portable.  Since some tests\n> tries to output strings containing '\\b' it is safer to use printf\n> here.  The usage of printf instead of echo is also preferred by POSIX.\n>\n> Signed-off-by: Marcel Telka <marcel@telka.sk>\n> ---\n>  t/t9902-completion.sh | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\n> index 963f865f27..ed3d03367e 100755\n> --- a/t/t9902-completion.sh\n> +++ b/t/t9902-completion.sh\n> @@ -73,7 +73,7 @@ _get_comp_words_by_ref ()\n>  print_comp ()\n>  {\n>  \tlocal IFS=$'\\n'\n> -\techo \"${COMPREPLY[*]}\" > out\n> +\tprintf '%s\\n' \"${COMPREPLY[*]}\" > out\n>  }\n\nThis has cooked in 'next' for some time already, and I'll merge this\ndown to 'master' anyway, but this being a script very much speicific\nto bash whose built-in echo we are using, the portability argument\nof \"echo\" made in the proposed log message does not quite apply to\nthis patch.\n\nThanks.\n"},{"id":"495453","messageId":"Zk-nswiCF-SnyxLE@telcontar","threadId":"61500","inReplyTo":"xmqqsey8tnny.fsf@gitster.g","subject":"Re: [PATCH] t/t9902-completion.sh: backslashes in echo","fromName":"Marcel Telka","fromEmail":"marcel@telka.sk","sentAt":"2024-05-23T20:31:47Z","receivedAt":"2024-05-23T20:31:57Z","isPatch":true,"sender":{"key":"marcel@telka.sk","avatar":"https://avatars.githubusercontent.com/u/3000173?v=4"},"body":"On Thu, May 23, 2024 at 10:59:13AM -0700, Junio C Hamano wrote:\n> Marcel Telka <marcel@telka.sk> writes:\n> \n> > The usage of backslashes in echo is not portable.  Since some tests\n> > tries to output strings containing '\\b' it is safer to use printf\n> > here.  The usage of printf instead of echo is also preferred by POSIX.\n> >\n> > Signed-off-by: Marcel Telka <marcel@telka.sk>\n> > ---\n> >  t/t9902-completion.sh | 2 +-\n> >  1 file changed, 1 insertion(+), 1 deletion(-)\n> >\n> > diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\n> > index 963f865f27..ed3d03367e 100755\n> > --- a/t/t9902-completion.sh\n> > +++ b/t/t9902-completion.sh\n> > @@ -73,7 +73,7 @@ _get_comp_words_by_ref ()\n> >  print_comp ()\n> >  {\n> >  \tlocal IFS=$'\\n'\n> > -\techo \"${COMPREPLY[*]}\" > out\n> > +\tprintf '%s\\n' \"${COMPREPLY[*]}\" > out\n> >  }\n> \n> This has cooked in 'next' for some time already, and I'll merge this\n> down to 'master' anyway, but this being a script very much speicific\n> to bash whose built-in echo we are using, the portability argument\n> of \"echo\" made in the proposed log message does not quite apply to\n> this patch.\n\nCould you please help me to understand how the bash is used to run the\nscript?\n\n$ head -n 1 t/t9902-completion.sh\n#!/bin/sh\n$\n\n\nThank you.\n\n-- \n+-------------------------------------------+\n| Marcel Telka   e-mail:   marcel@telka.sk  |\n|                homepage: http://telka.sk/ |\n+-------------------------------------------+\n"},{"id":"495455","messageId":"CAPig+cRddr=JTVvkh5xkptag_1C5-z1t9Pzr_OdcGFSVwRg3vg@mail.gmail.com","threadId":"61500","inReplyTo":"Zk-nswiCF-SnyxLE@telcontar","subject":"Re: [PATCH] t/t9902-completion.sh: backslashes in echo","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2024-05-23T21:06:00Z","receivedAt":"2024-05-23T21:06:13Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Thu, May 23, 2024 at 4:32 PM Marcel Telka <marcel@telka.sk> wrote:\n> On Thu, May 23, 2024 at 10:59:13AM -0700, Junio C Hamano wrote:\n> > Marcel Telka <marcel@telka.sk> writes:\n> > > The usage of backslashes in echo is not portable.  Since some tests\n> > > tries to output strings containing '\\b' it is safer to use printf\n> > > here.  The usage of printf instead of echo is also preferred by POSIX.\n> >\n> > This has cooked in 'next' for some time already, and I'll merge this\n> > down to 'master' anyway, but this being a script very much speicific\n> > to bash whose built-in echo we are using, the portability argument\n> > of \"echo\" made in the proposed log message does not quite apply to\n> > this patch.\n>\n> Could you please help me to understand how the bash is used to run the\n> script?\n>\n> $ head -n 1 t/t9902-completion.sh\n> #!/bin/sh\n\nLooking a bit farther in t9902, you'll find:\n\n    . ./lib-bash.sh\n\nAnd if you look inside `lib-bash.sh`, you'll see that, if the\ncurrently-running shell is not Bash, it aborts the current script and\nre-runs it under Bash.\n\nBut Junio's point was that t9902 is dedicated to testing Bash-specific\nfunctionality, so the commit message's justification to avoid this\nnon-POSIX behavior isn't necessarily a good justification for the\nchange. (He wasn't saying that the change itself was unwelcome, just\nthat the commit message wasn't convincing.)\n"},{"id":"495482","messageId":"Zk-5YCKSO32vPKDP@telcontar","threadId":"61500","inReplyTo":"CAPig+cRddr=JTVvkh5xkptag_1C5-z1t9Pzr_OdcGFSVwRg3vg@mail.gmail.com","subject":"Re: [PATCH] t/t9902-completion.sh: backslashes in echo","fromName":"Marcel Telka","fromEmail":"marcel@telka.sk","sentAt":"2024-05-23T21:47:12Z","receivedAt":"2024-05-23T21:47:15Z","isPatch":true,"sender":{"key":"marcel@telka.sk","avatar":"https://avatars.githubusercontent.com/u/3000173?v=4"},"body":"On Thu, May 23, 2024 at 05:06:00PM -0400, Eric Sunshine wrote:\n> On Thu, May 23, 2024 at 4:32 PM Marcel Telka <marcel@telka.sk> wrote:\n> > On Thu, May 23, 2024 at 10:59:13AM -0700, Junio C Hamano wrote:\n> > > Marcel Telka <marcel@telka.sk> writes:\n> > > > The usage of backslashes in echo is not portable.  Since some tests\n> > > > tries to output strings containing '\\b' it is safer to use printf\n> > > > here.  The usage of printf instead of echo is also preferred by POSIX.\n> > >\n> > > This has cooked in 'next' for some time already, and I'll merge this\n> > > down to 'master' anyway, but this being a script very much speicific\n> > > to bash whose built-in echo we are using, the portability argument\n> > > of \"echo\" made in the proposed log message does not quite apply to\n> > > this patch.\n> >\n> > Could you please help me to understand how the bash is used to run the\n> > script?\n> >\n> > $ head -n 1 t/t9902-completion.sh\n> > #!/bin/sh\n> \n> Looking a bit farther in t9902, you'll find:\n> \n>     . ./lib-bash.sh\n> \n> And if you look inside `lib-bash.sh`, you'll see that, if the\n> currently-running shell is not Bash, it aborts the current script and\n> re-runs it under Bash.\n\nThanks for the pointer!\n\nInteresting.  I came to this issue because the test failed here due to\nthe echo.  So apparently the re-run under bash didn't happen here for\nsome reason or bash's echo behaved differently?  I need to dig into it\nagain to find what's going on.\n\n> But Junio's point was that t9902 is dedicated to testing Bash-specific\n> functionality, so the commit message's justification to avoid this\n> non-POSIX behavior isn't necessarily a good justification for the\n> change. (He wasn't saying that the change itself was unwelcome, just\n> that the commit message wasn't convincing.)\n\nSure.  I understand the point.  I just had an impression that the test\nis running under POSIX sh (/bin/sh), not bash, because it failed here\n(see above).\n\nOTOH, it seems that the fix is maybe not needed because it is solving a\nnon-problem.\n\n\nThank you.\n\n-- \n+-------------------------------------------+\n| Marcel Telka   e-mail:   marcel@telka.sk  |\n|                homepage: http://telka.sk/ |\n+-------------------------------------------+\n"},{"id":"495485","messageId":"Zk_FiYd8uk-P5jIi@telcontar","threadId":"61500","inReplyTo":"Zk-5YCKSO32vPKDP@telcontar","subject":"Re: [PATCH] t/t9902-completion.sh: backslashes in echo","fromName":"Marcel Telka","fromEmail":"marcel@telka.sk","sentAt":"2024-05-23T22:39:05Z","receivedAt":"2024-05-23T22:39:08Z","isPatch":true,"sender":{"key":"marcel@telka.sk","avatar":"https://avatars.githubusercontent.com/u/3000173?v=4"},"body":"On Thu, May 23, 2024 at 11:47:13PM +0200, Marcel Telka wrote:\n> Interesting.  I came to this issue because the test failed here due to\n> the echo.  So apparently the re-run under bash didn't happen here for\n> some reason or bash's echo behaved differently?  I need to dig into it\n> again to find what's going on.\n\nOkay, I found the cause.  Bash on OpenIndiana is compiled with\n--enable-xpg-echo-default so escape sequencies are expanded by default.\n\n> OTOH, it seems that the fix is maybe not needed because it is solving a\n> non-problem.\n\nThere is a problem, but definitely the justification in the commit\nmessage is not accurate because we do not care about POSIX here at all.\nAlso maybe it would be better/simpler to use `echo -E` instead of\n`printf`, but I'm not sure here.\n\n\nThanks.\n\n-- \n+-------------------------------------------+\n| Marcel Telka   e-mail:   marcel@telka.sk  |\n|                homepage: http://telka.sk/ |\n+-------------------------------------------+\n"},{"id":"495486","messageId":"Zk_HFkm2aymJXGZU@telcontar","threadId":"61500","inReplyTo":"Zk_FiYd8uk-P5jIi@telcontar","subject":"Re: [PATCH] t/t9902-completion.sh: backslashes in echo","fromName":"Marcel Telka","fromEmail":"marcel@telka.sk","sentAt":"2024-05-23T22:45:42Z","receivedAt":"2024-05-23T22:45:45Z","isPatch":true,"sender":{"key":"marcel@telka.sk","avatar":"https://avatars.githubusercontent.com/u/3000173?v=4"},"body":"On Fri, May 24, 2024 at 12:39:06AM +0200, Marcel Telka wrote:\n> On Thu, May 23, 2024 at 11:47:13PM +0200, Marcel Telka wrote:\n> > Interesting.  I came to this issue because the test failed here due to\n> > the echo.  So apparently the re-run under bash didn't happen here for\n> > some reason or bash's echo behaved differently?  I need to dig into it\n> > again to find what's going on.\n> \n> Okay, I found the cause.  Bash on OpenIndiana is compiled with\n> --enable-xpg-echo-default so escape sequencies are expanded by default.\n> \n> > OTOH, it seems that the fix is maybe not needed because it is solving a\n> > non-problem.\n> \n> There is a problem, but definitely the justification in the commit\n> message is not accurate because we do not care about POSIX here at all.\n> Also maybe it would be better/simpler to use `echo -E` instead of\n> `printf`, but I'm not sure here.\n\nReading again the commit message I proposed[1] I think it is okay.\n\n[1] https://lore.kernel.org/git/Zkdk7R9GIfsyQjkc@telcontar/\n\n-- \n+-------------------------------------------+\n| Marcel Telka   e-mail:   marcel@telka.sk  |\n|                homepage: http://telka.sk/ |\n+-------------------------------------------+\n"},{"id":"495491","messageId":"xmqqcypcqgf9.fsf@gitster.g","threadId":"61500","inReplyTo":"Zk_FiYd8uk-P5jIi@telcontar","subject":"Re: [PATCH] t/t9902-completion.sh: backslashes in echo","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-05-23T23:03:54Z","receivedAt":"2024-05-23T23:04:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Marcel Telka <marcel@telka.sk> writes:\n\n> Okay, I found the cause.  Bash on OpenIndiana is compiled with\n> --enable-xpg-echo-default so escape sequencies are expanded by default.\n>\n>> OTOH, it seems that the fix is maybe not needed because it is solving a\n>> non-problem.\n>\n> There is a problem, but definitely the justification in the commit\n> message is not accurate because we do not care about POSIX here at all.\n> Also maybe it would be better/simpler to use `echo -E` instead of\n> `printf`, but I'm not sure here.\n\nHow \"portable\" is \"echo -E\"?  It apparently is not listd in [*], but\nit should probably not matter as we are doing this in bash.\n\nprintf is a kosher way whose behaviour is pretty well standardized\nespecially with respect to \"%s\".  As I said that I was going to\nmerge it down to 'master' already, it is now part of 'master'.\nUse of printf there may hopefully educate folks to think twice\nbefore using 'echo' on unknown data.\n\nBy the way, it makes me feel funny that we are talking about \"POSIX\nportability\" when reviewing a change like this:\n\n         print_comp ()\n         {\n                local IFS=$'\\n'\n        -\techo \"${COMPREPLY[*]}\" > out\n        +\tprintf '%s\\n' \"${COMPREPLY[*]}\" > out\n         }\n\nWith \"${ARRAY[*]}\", POSIX portability is totally out of the water\nanyway, regardless of the echo/printf issue ;-).\n\n\n[Reference]\n\n* https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html\n"},{"id":"495493","messageId":"CAPig+cRme82m-09_yhiMx_O3CgnoAtEZkdFiZTX46yTZ0M0QpQ@mail.gmail.com","threadId":"61500","inReplyTo":"xmqqcypcqgf9.fsf@gitster.g","subject":"Re: [PATCH] t/t9902-completion.sh: backslashes in echo","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2024-05-23T23:14:34Z","receivedAt":"2024-05-23T23:14:46Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Thu, May 23, 2024 at 7:03 PM Junio C Hamano <gitster@pobox.com> wrote:\n> Marcel Telka <marcel@telka.sk> writes:\n> > There is a problem, but definitely the justification in the commit\n> > message is not accurate because we do not care about POSIX here at all.\n> > Also maybe it would be better/simpler to use `echo -E` instead of\n> > `printf`, but I'm not sure here.\n>\n> How \"portable\" is \"echo -E\"?  It apparently is not listd in [*], but\n> it should probably not matter as we are doing this in bash.\n>\n> printf is a kosher way whose behaviour is pretty well standardized\n> especially with respect to \"%s\".  As I said that I was going to\n> merge it down to 'master' already, it is now part of 'master'.\n> Use of printf there may hopefully educate folks to think twice\n> before using 'echo' on unknown data.\n\nIndeed. Seeing`echo $VAR` used always makes my reading hiccup since\nit's never immediately clear (without consulting additional context)\nwhether the value of VAR starts with a hyphen or has embedded escapes.\nOn the other hand, `printf \"%s\" $VAR` doesn't suffer from this\nproblem, so this change is welcome regardless.\n"},{"id":"495494","messageId":"Zk_PhSQU2vefKkjq@telcontar","threadId":"61500","inReplyTo":"xmqqcypcqgf9.fsf@gitster.g","subject":"Re: [PATCH] t/t9902-completion.sh: backslashes in echo","fromName":"Marcel Telka","fromEmail":"marcel@telka.sk","sentAt":"2024-05-23T23:21:41Z","receivedAt":"2024-05-23T23:21:44Z","isPatch":true,"sender":{"key":"marcel@telka.sk","avatar":"https://avatars.githubusercontent.com/u/3000173?v=4"},"body":"On Thu, May 23, 2024 at 04:03:54PM -0700, Junio C Hamano wrote:\n> Marcel Telka <marcel@telka.sk> writes:\n> \n> > Okay, I found the cause.  Bash on OpenIndiana is compiled with\n> > --enable-xpg-echo-default so escape sequencies are expanded by default.\n> >\n> >> OTOH, it seems that the fix is maybe not needed because it is solving a\n> >> non-problem.\n> >\n> > There is a problem, but definitely the justification in the commit\n> > message is not accurate because we do not care about POSIX here at all.\n> > Also maybe it would be better/simpler to use `echo -E` instead of\n> > `printf`, but I'm not sure here.\n> \n> How \"portable\" is \"echo -E\"?  It apparently is not listd in [*], but\n> it should probably not matter as we are doing this in bash.\n\nAgreed.\n\n> printf is a kosher way whose behaviour is pretty well standardized\n> especially with respect to \"%s\".  As I said that I was going to\n> merge it down to 'master' already, it is now part of 'master'.\n> Use of printf there may hopefully educate folks to think twice\n> before using 'echo' on unknown data.\n> \n> By the way, it makes me feel funny that we are talking about \"POSIX\n> portability\" when reviewing a change like this:\n> \n>          print_comp ()\n>          {\n>                 local IFS=$'\\n'\n>         -\techo \"${COMPREPLY[*]}\" > out\n>         +\tprintf '%s\\n' \"${COMPREPLY[*]}\" > out\n>          }\n> \n> With \"${ARRAY[*]}\", POSIX portability is totally out of the water\n> anyway, regardless of the echo/printf issue ;-).\n\nThe commit message does not say that this change is to make the code\nPOSIX portable ;-).  It silently assumes the portability is related to\nbash only.\n\n-- \n+-------------------------------------------+\n| Marcel Telka   e-mail:   marcel@telka.sk  |\n|                homepage: http://telka.sk/ |\n+-------------------------------------------+\n"}]}