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

From: Marcel Telka <[email-masked]>
Date: Thu, 23 May 2024 22:31:47 +0200

On Thu, May 23, 2024 at 10:59:13AM -0700, Junio C Hamano wrote:
> Marcel Telka <[email-masked]> writes:
> 
> > The usage of backslashes in echo is not portable.  Since some tests
> > tries to output strings containing '\b' it is safer to use printf
> > here.  The usage of printf instead of echo is also preferred by POSIX.
> >
> > Signed-off-by: Marcel Telka <[email-masked]>
> > ---
> >  t/t9902-completion.sh | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
> > index 963f865f27..ed3d03367e 100755
> > --- a/t/t9902-completion.sh
> > +++ b/t/t9902-completion.sh
> > @@ -73,7 +73,7 @@ _get_comp_words_by_ref ()
> >  print_comp ()
> >  {
> >  	local IFS=$'\n'
> > -	echo "${COMPREPLY[*]}" > out
> > +	printf '%s\n' "${COMPREPLY[*]}" > out
> >  }
> 
> This has cooked in 'next' for some time already, and I'll merge this
> down to 'master' anyway, but this being a script very much speicific
> to bash whose built-in echo we are using, the portability argument
> of "echo" made in the proposed log message does not quite apply to
> this patch.

Could you please help me to understand how the bash is used to run the
script?

$ head -n 1 t/t9902-completion.sh
#!/bin/sh
$

Thank you.

-- 
+-------------------------------------------+
| Marcel Telka   e-mail:   [email-masked]  |
|                homepage: http://telka.sk/ |
+-------------------------------------------+