$ printf \'apple\' | wc -m
5
$ echo \'apple\' | wc -m
6
Why printf prints 5 and echo prints 6 characters?
Printf does not give new line after execution of command but echo gives new linw after the execution of command. Please see the bewlow code output.
Use of Printf:
a=0
while [ $a -lt 10 ]
do
printf $a
a=expr $a + 1
done
o/p: 0123456789
Use of Echo:
a=0
while [ $a -lt 10 ]
do
echo $a
a=expr $a + 1
done
o/p:It will print in a column wise as this window not taking as a column wise please try to execute this code it will give better understanding.
0 1 2 3 4 5 6 7 8 9
you can remove the new line in echo by giving the bewlow command echo -n $a