You are right. echo isn't as portable as printf and you are right to point it out.
I'm using it since I have echo available on my operating system and it is a little bit easier to use than printf. And for most GNU/Linux distributions out there, this is also the case. This article is also an opportunity for people not confortable with Shell scripts to discover some of its utility programs so I figured why not. Two birds one stone, right?
If someone is using a distribution that does not include echo, I'll assume this person is also aware of how to edit this script and make it portable again so I didn't worry about it too much when writing this article.
But again you are totally right about its portability. Especially when it comes to using echo with ZSH or in Bash.
I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
I'm more on about things like echo -n not being portable than echo itself not existing. It does different things depending on the shell, and if you try to stick to POSIX you're not going to use those options anyway.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi Ben and thanks for your answer!
You are right.
echo
isn't as portable asprintf
and you are right to point it out.I'm using it since I have
echo
available on my operating system and it is a little bit easier to use thanprintf
. And for most GNU/Linux distributions out there, this is also the case. This article is also an opportunity for people not confortable with Shell scripts to discover some of its utility programs so I figured why not. Two birds one stone, right?If someone is using a distribution that does not include
echo
, I'll assume this person is also aware of how to edit this script and make it portable again so I didn't worry about it too much when writing this article.But again you are totally right about its portability. Especially when it comes to using
echo
with ZSH or in Bash.I'm more on about things like
echo -n
not being portable thanecho
itself not existing. It does different things depending on the shell, and if you try to stick to POSIX you're not going to use those options anyway.