Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
Required fields*
11
25
A lot of early unix development happened in isolation, and good software engineering principles like 'when you change the interface, change the name' were not applied.
As a note, the one (and maybe only) advantage of having echo expand the \x sequences as opposed to the shell as part of the quoting syntax is that you can then output a NUL byte (another arguably mis-design of Unix is those null-delimited strings, where half the system calls (like execve()) can't take arbitrary sequences of bytes)
@StéphaneChazelas Is there a reason why you would avoid using the word local in your "plain echo" function? Wouldn't it better be echo() { local IFS=" " ; printf '%s\n' "$*" ;} without the subshell?
so for instance, it's difficult to output "-n" with echo in many shells. +1 on that! On bash on Ubuntu 18.04. echo "-n" should output -n. Instead, it outputs nothing since it accepts that as the same thing as the -n flag. echo -- "-n" should solve that and output -n, but it doesn't. It outputs -- -n instead. I see your point very well now. printf is better.
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
complete the sentence: my question is about...
use tags that describe things or concepts that are essential, not incidental to your question
echoexpand the\xsequences as opposed to the shell as part of the quoting syntax is that you can then output a NUL byte (another arguably mis-design of Unix is those null-delimited strings, where half the system calls (likeexecve()) can't take arbitrary sequences of bytes)localin your "plain echo" function? Wouldn't it better beecho() { local IFS=" " ; printf '%s\n' "$*" ;}without the subshell?so for instance, it's difficult to output "-n" with echo in many shells. +1 on that! On bash on Ubuntu 18.04.echo "-n"should output-n. Instead, it outputs nothing since it accepts that as the same thing as the-nflag.echo -- "-n"should solve that and output-n, but it doesn't. It outputs-- -ninstead. I see your point very well now.printfis better.