Re: [PATCH] test-lib.sh: use printf instead of echo
From: Junio C Hamano <hidden>
Date: 2016-06-15 23:00:23
Jonathan Nieder [off-list ref] writes:
Junio C Hamano wrote: ...quoted
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?