Linux.com

printf & echo

Link to this post 20 May 09

what r the diferences b/w printf and echo cmd.........
is use of printf better than echo? how...........

Link to this post 20 May 09

well, it depends on what you want to do
if you want just a basic display, echo is enough
printf allows you to display with formatting features. If you're
familiar with c, it's similar to c's printf
I'll give you some examples

# i=5

1. echo
# echo $i
5
#

2. printf
# printf $i
5#printf "$i\n"
5
#

# printf "%02d\n" $i
05
#

As you must have noticed with printf the
newline character '\n' is not automatically added as in
echo

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board