printf barely has any options of its own — control happens through the
format string; the exception is -v, which writes the result into a
variable instead of printing it. echo's options, by contrast, define its
whole behavior: -n drops the trailing newline, -e/-E turn
interpretation of \n/\t in the argument on and off — the default
behavior of -e differs between bash's echo and /bin/echo, which is
why printf is more reliable in scripts.
| Option |
What it does |
Example |
-v var |
printf: store the result in a variable instead of printing it. |
printf -v stamp '%(%Y%m%d)T' -1 |
-n |
echo: suppress the trailing newline. |
echo -n "no newline" |
-e |
echo: interpret backslash escapes (\n, \t) in the argument. |
echo -e "a\tb" |
-E |
echo: do not interpret backslash escapes (the default behavior). |
echo -E "a\tb" |
Nothing found. Try a shorter query.