Re: [PATCH] t/t9902-completion.sh: backslashes in echo
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- May 23, 2024, 23:14 UTC
- Message-ID
- <CAPig+cRme82m-09_yhiMx_O3CgnoAtEZkdFiZTX46yTZ0M0QpQ@mail.gmail.com>
- In-Reply-To
- <xmqqcypcqgf9.fsf@gitster.g>
On Thu, May 23, 2024 at 7:03 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 14 quoted lines
> Marcel Telka <marcel@telka.sk> writes: > > 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. > > 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.
Indeed. Seeing`echo $VAR` used always makes my reading hiccup since it's never immediately clear (without consulting additional context) whether the value of VAR starts with a hyphen or has embedded escapes. On the other hand, `printf "%s" $VAR` doesn't suffer from this problem, so this change is welcome regardless.