Availability: echo vs. printf?


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 11-09-2014
Availability: echo vs. printf?

Hello,

For some reason i dont remember, i currently believe (but beeing unsure) that printf is available on more diffrent systems (unix, bsd, linux, ??) than echo is.

Could someone please enlighten me, whether this is true or not?
Thank you

PS:
I just found pages about the diffrences of the two commands, but not where they are available or not.
# 2  
Old 11-09-2014
The printf utility has been almost universally available for more than 2 decades and is a built-in in almost all current shells. There is a large set of conversion specifiers that behave the same way on all systems and in all shells. (Some shells provide extensions that supply additional conversion specifiers.)

The echo utility has been universally available for more than 4 decades and is a built-in in almost all current shells. The meaning of various options and backslash escape sequences recognized by echo varies from system to system and shell to shell.
This User Gave Thanks to Don Cragun For This Post:
sea (11-09-2014)
# 3  
Old 11-09-2014
So, to say it simple ( one could also say):
* Both should be available on almost all systems?
* And to print a simple "Hello World", the main reason to choose one or the other tool would be personal preference?
# 4  
Old 11-09-2014
As I have said in dozens of other threads in these forums: if the first character of the first argument is a minus sign, if any argument contains a backslash, if you do not want to have a newline printed at the end of the output, or if any argument contains user-supplied data; use printf, not echo. Otherwise, it doesn't matter whether you use printf or echo.
These 2 Users Gave Thanks to Don Cragun For This Post:
RavinderSingh13 (11-10-2014) sea (11-09-2014)
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Redhat: High Availability mzainal Red Hat 1 06-08-2015 09:48 AM
High availability zineb06 Solaris 1 05-13-2015 11:06 AM
Grep behaves diffrent upon printf or echo output sea Shell Programming and Scripting 4 10-14-2014 03:58 AM
Managing output... echo or printf? maverick72 Shell Programming and Scripting 2 08-26-2014 04:10 PM
Checking SQL DB Availability SeaSoul Shell Programming and Scripting 4 02-13-2014 06:49 PM
iscsi high availability jobycxa UNIX for Dummies Questions & Answers 0 04-10-2012 04:55 AM
Check File availability cratercrabs Shell Programming and Scripting 3 10-24-2011 04:50 AM
printf/echo in a second script miltonrods Shell Programming and Scripting 2 04-14-2011 01:51 PM
\n in ksh using echo & printf dahlia84 Shell Programming and Scripting 7 11-15-2010 09:43 AM
Track availability of computers petel1 Homework & Coursework Questions 4 05-28-2010 01:56 PM
Checking availability of service satheeshkr_cse Shell Programming and Scripting 2 02-17-2010 09:59 AM
advanced echo/printf proactiveaditya Shell Programming and Scripting 2 10-16-2009 05:18 AM
How to correctly use an echo inside an echo? mokachoka UNIX for Dummies Questions & Answers 3 09-19-2009 11:40 PM
Check Database availability? megh Solaris 2 11-07-2008 11:35 AM
Printer availability agsarm1971 Solaris 2 04-01-2008 12:56 PM