echo prints its argument followed by a newline. With multiple arguments, they are separated by spaces. Depending on the unix variant, the shell and the shell options, it may also interpret some escape sequences beginning with
\, and it may treat the first argument(s) as options if they start with
printf interprets its first argument as a format, and subsequent arguments as arguments to the
% specifiers. No newline is added unless you specify one. In the first argument, all characters except two are interpreted literally:
% starts a printf specifier, and
\ starts an escape sequence (e.g.
\n for a newline character).
Because different shells work differently,
echo "$string" does not always print the specified string plus a newline. A reliable way of printing a string is
printf %s "$string". If you want a newline after the string, write
printf '%s\n' "$string".
In your case, assuming that
blah doesn't start with a
- or contain
\, the only difference between the two commands is that
echo adds a newline and