From: Jon LaBadie on 13 Apr 2010 18:17 Still on echo vs. printf, I forgot to note that both echo and printf are available as executables (/bin/echo and /bin/printf) and as shell builtins in many shells. However printf is also part of many other unix/linux programming languages including I believe, C, awk, perl, php, python, ruby, java, javascript, ... while echo is not. Thus your learning about printf while shell programming is also preparing you for other languages.
From: Jon LaBadie on 13 Apr 2010 18:32 Seebs wrote: > On 2010-04-13, thdyoung(a)googlemail.com <thdyoung(a)googlemail.com> wrote: >> i don't want to interfere but folk shy away from man pages coz they're >> so darned bad to read > > No, they really aren't. > .... >> all us lurkers glean vast amounts of learning from these groups - of >> course, we do: we are here to learn coz it is far better than the man >> pages > > It's not better, it's *different*. It's aimed at solving a different kind > of problem. Failing to read the man pages first is insulting and rude; it's > a statement to everyone else that ten seconds of the time of every single > other reader in the newsgroup, and a minute or more from a few of them, is > worth much less than five minutes of your time. I feel a necessary word is regularly omitted from the term "man page". These pages were originally included in the User's, the Programmer's, and the Administrator's REFERENCE Manual. They are not intended to be tutorials or how-to's but instead they are exceedingly valuable online reference information. As a reference, they should often the first source one checks for details. You don't ask on the net how to spell, pronounce, or the meaning of a word. You check a reference such as a dictionary. A reference can be daunting when first encountered, but repeated usage will lead to more efficient usage and a higher comfort level.
From: Seebs on 13 Apr 2010 18:50 On 2010-04-13, Jon LaBadie <jlabadie(a)aXcXm.org> wrote: > However printf is also part of many other unix/linux programming languages > including I believe, C, awk, perl, php, python, ruby, java, javascript, ... > while echo is not. Thus your learning about printf while shell programming > is also preparing you for other languages. .... with the slight caveat that shell printf does something gratuitously useless with %c. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Chris F.A. Johnson on 13 Apr 2010 20:51 On 2010-04-13, houghi wrote: > Jon LaBadie wrote: >> If you are going to do simple literal text that does not contain escape >> sequences, go ahead and use echo. For example: >> >> echo "Hello World!" >> >> But is that easier than: >> >> printf "Hello World!\n" >> >> Well I guess it is harder because you have to add the '\n' in printf. > > And here you go and confuse me again. :-/ First I need all the %s and >%d and stuff and now I don't. So yes, for _me_ it is harder. Much > harder. > > I will leave it at that and again thank you all for your efforts. Try this function as a replacement for echo: put() { printf "%s\n" "$*" } Even call it echo if you like. -- Chris F.A. Johnson, author <http://shell.cfajohnson.com/> =================================================================== Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== ===== and is released under the GNU General Public Licence =====
From: Mart Frauenlob on 14 Apr 2010 08:21
On 13.04.2010 18:28, houghi wrote: > I probably didn't understand it, which is logical as I am not as smart > as most others. ;-) Self fulfilling prophecy. If your brain would be a unix shell, your thoughts would be commands. So you program yourself like: printf "I'm not smart!\n" But you expect it to output: I'm smart! So ... change your commands :) |