Bash 5 reference · Shell Builtins and Syntax
printf (Bash builtin)
Print formatted text with format specifiers like %s, %d and %.2f; more portable and predictable than echo.
Bash 5
Syntax
printf FORMAT [ARGUMENT...]
Parameters
| Parameter | Description |
|---|---|
%s / %d / %f |
String, integer and floating-point placeholders. |
%-10s |
Left-align in a 10-character field. |
%.2f |
Two decimal places. |
-v VAR |
Store the result in a variable instead of printing. |
Examples
printf '%-6s %5s\n' item price
printf '%-6s %5.2f\n' mug 8.5 teapot 24
Output
item price mug 8.50 teapot 24.00
Run this on your computer — see “Get Started” for setup.
printf -v stamp '%04d-%02d-%02d' 2026 1 5
echo "$stamp"
echo -n 'no newline'; echo ' <- echo -n'
Output
2026-01-05 no newline <- echo -n
Run this on your computer — see “Get Started” for setup.
echo handles options and backslashes differently between shells; use printf in scripts when the output format matters.
Related
read· Read a line from standard input into variables, splitting on IFS; use -r to keep backslashes and -p for a prompt.here-document· Feed multiple lines to a command with <<EOF; quote the marker to stop variable expansion, use <<- to strip tabs.- Bash Here Documents and printf · tutorial