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

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

# printf "%02d\n" $i

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

Who we are ?

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

More About the foundation...

Frequent Questions

Linux Training / Board

/** BC-056 Ameex changes to add tracking code - 2016-01-22 **/ ?>