git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] t/t9902-completion.sh: backslashes in echo

From
Marcel Telka <marcel@telka.sk>
Date
May 23, 2024, 23:21 UTC
Message-ID
<Zk_PhSQU2vefKkjq@telcontar>
In-Reply-To
<xmqqcypcqgf9.fsf@gitster.g>
On Thu, May 23, 2024 at 04:03:54PM -0700, Junio C Hamano wrote:
Show 15 quoted lines
> Marcel Telka <marcel@telka.sk> writes:
> 
> > Okay, I found the cause.  Bash on OpenIndiana is compiled with
> > --enable-xpg-echo-default so escape sequencies are expanded by default.
> >
> >> OTOH, it seems that the fix is maybe not needed because it is solving a
> >> non-problem.
> >
> > There is a problem, but definitely the justification in the commit
> > message is not accurate because we do not care about POSIX here at all.
> > Also maybe it would be better/simpler to use `echo -E` instead of
> > `printf`, but I'm not sure here.
> 
> How "portable" is "echo -E"?  It apparently is not listd in [*], but
> it should probably not matter as we are doing this in bash.
Agreed.
Show 18 quoted lines
> printf is a kosher way whose behaviour is pretty well standardized
> especially with respect to "%s".  As I said that I was going to
> merge it down to 'master' already, it is now part of 'master'.
> Use of printf there may hopefully educate folks to think twice
> before using 'echo' on unknown data.
> 
> By the way, it makes me feel funny that we are talking about "POSIX
> portability" when reviewing a change like this:
> 
>          print_comp ()
>          {
>                 local IFS=$'\n'
>         -	echo "${COMPREPLY[*]}" > out
>         +	printf '%s\n' "${COMPREPLY[*]}" > out
>          }
> 
> With "${ARRAY[*]}", POSIX portability is totally out of the water
> anyway, regardless of the echo/printf issue ;-).

The commit message does not say that this change is to make the code POSIX portable ;-). It silently assumes the portability is related to bash only.

-- 
+-------------------------------------------+
| Marcel Telka   e-mail:   marcel@telka.sk  |
|                homepage: http://telka.sk/ |
+-------------------------------------------+
Previous: Eric Sunshine
Message 10 of 10 in “t/t9902-completion.sh: backslashes in echo”
  1. t/t9902-completion.sh: backslashes in echoMarcel Telka, May 17, 2024
  2. Junio C HamanoMay 23, 2024
  3. Marcel TelkaMay 23, 2024
  4. Eric SunshineMay 23, 2024
  5. Marcel TelkaMay 23, 2024
  6. Marcel TelkaMay 23, 2024
  7. Marcel TelkaMay 23, 2024
  8. Junio C HamanoMay 23, 2024
  9. Eric SunshineMay 23, 2024
  10. Marcel TelkaMay 23, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.