[PATCH] D25929: Add llvm-echo command.
Bob Haarman via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 25 16:10:34 PDT 2016
inglorion added a comment.
As for adding features, such as the -n option, I would like to make the case for modding those to using printf. echo is non-portable because different implementations have different, and sometimes conflicting features. printf behaves much more predictably and has more features. For this reason, many people advise to use printf instead of echo. Unfortunately, many people's first instinct is to use echo. I think it's a good idea to make sure this works consistently, regardless of what variant of echo may be installed on someone's system or listed first in their PATH.
For the purpose of consistent behavior, I feel it's good enough to have a very simple implementation of echo that just prints its arguments, as your implementation does. I don't see as strong a case for implementing anything more advanced. It would require more work to implement, and we would have to decide if we're going to support -n, and if we're going to support a way to print a literal -n, and whatever we decide would probably surprise someone somewhere. It seems to me we might as well go with the simple implementation and tell people to use printf if they want something more advanced. We have the benefit that if someone tries to use -n to omit the final newline, the simple implementation will very obviously not do what they want, which will hopefully cause them to look for a solution and use printf instead. That, in turn, would then work if someone were to copy-paste the command line from the lit test into their shell, regardless of what variant of echo is on their system. This is much better than what we currently have, where one can use echo to write something that works on one system and misbehaves on another.
More information about the llvm-commits