I am new to BASH and learnt that both printf and echo write to the standard output. But, I came through the following example which reads an expression from input and computes the result to accuracy of 3 decimal places:
read exp
printf "%.3f\n" "$(echo $exp | bc -l)"
I don't get why echo is passed here as an argument in the the printf
statement. Is there any other
way to represent the statement using only echo
?
printf
builtin asbc
alone won't round results – Sylvain Pineau Oct 29 '14 at 16:35