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

Re: [PATCH] test-lib.sh: use printf instead of echo

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 20, 2014, 16:42 UTC
Message-ID
<xmqq4n2s255z.fsf@gitster.dls.corp.google.com>
In-Reply-To
<20140320001718.GM15625@google.com>
Jonathan Nieder <jrnieder@gmail.com> writes:
Show 10 quoted lines
> Junio C Hamano wrote:
> ...
>> I am a bit reluctant to name the helper "sane_echo" to declare "echo
>> that interprets backslashes in the string is insane", though.  For
>> these "print a single line" uses, we are only interested in using a
>> subset of the features offered by 'echo', but that does not mean the
>> other features we do not want to trigger in our use is of no use to
>> any sane person.
>
> In a portable script, uncareful use of 'echo' is always insane.

I agree that makes sense and I actually think that it is a bit stronger than that. If a script is meant to be portable, there is no way to use "echo" on a string whose contents is unknown sanely. There is no "careful use is OK".

> In a script tailored to an environment where echo behaves consistently
> it is perfectly reasonable to use 'echo', but that's a different
> story.  In the context of git, saying "Here is the thing you should
> always use instead of echo" is a good thing, in my opinion.

That is true in my opinion, but that thing is also what you should always use instead of "printf '%s\n'". A guideline more useful for the users is "Here is the thing you should always use when literally emitting a single line.", isn't it?

Previous: Jonathan NiederNext: Johannes Sixt
Message 9 of 14 in “test-lib.sh: use printf instead of echo”
  1. test-lib.sh: use printf instead of echoUwe Storbeck, Mar 14, 2014
  2. Jonathan NiederMar 15, 2014
  3. Junio C HamanoMar 17, 2014
  4. Jonathan NiederMar 18, 2014
  5. Junio C HamanoMar 19, 2014
  6. David KastrupMar 19, 2014
  7. Junio C HamanoMar 19, 2014
  8. Jonathan NiederMar 20, 2014
  9. Junio C HamanoMar 20, 2014
  10. Johannes SixtMar 15, 2014
  11. Uwe StorbeckMar 17, 2014
  12. test-lib.sh: use printf instead of echoUwe Storbeck, Mar 17, 2014
  13. test-lib.sh: do not "echo" externally supplied stringsUwe Storbeck, Mar 18, 2014
  14. Junio C HamanoMar 18, 2014

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.