Format and print data.
Write the formatted arguments to the standard output under the control of the format.
printf format [argument]…
The format characters and their meanings are:
" double quote
NNN character with octal value NNN (0 to 3 digits)
a alert (BEL)
c produce no further output
f form feed
v vertical tab
xNNN byte with hexadecimal value NNN (1 to 3 digits)
uNNNN character with hexadecimal value NNNN (4 digits)
character with hexadecimal value NNNNNNNN (8 digits)
&qt;&qt; a single &qt;
&qt;b ARGUMENT as a string with &qt;&qt;&qt; escapes interpreted
&qt;Wd Integer &qt;W&qt;&qt; digits wide xxxx
&qt;W.De Scientific notation x.xxxx e nnn. float, double
&qt;W.Df Fixed format xx.xxxx. float, double
&qt;W.Dg Variable &qt;W&qt;&qt; digits wide,&qt;D&qt;&qt; decimals xxxx.xx
&qt;q Output the corresponding argument in a format that can be
reused as shell input
&qt;s Character string char
and all C format specifications ending with one of diouxXfeEgGcs, with
ARGUMENTs converted to proper type first. Variable widths are handled.
e.g. &qt; ooo&qt;&qt; = an octal number, &qt;xhhh&qt;&qt; = a hex numberThe format is a character string which contains three types of objects:
Plain characters, which are simply copied to standard output,
Character escape sequences, which are converted and copied to standard output,
Format specifications, each of which causes printing of the next successive argument.
The format is reused as necessary to consume all of the arguments. If the format requires more arguments than are supplied, the extra format specifications behave as if a zero value or null string, as appropriate, had been supplied.
The return value is zero on success, non-zero on failure.
$ printf "Two separate
" # Using
to start a new line
printf "Hello, $USER.
" # Text followed by variable $USER
printf "Distance = &qt;5d Miles" $distance # Display an integer variable
Distance = 27 Miles
# Print text interspersed with command results
printf "This is &qt;uname -s&qt; running on a &qt;uname -m&qt; processor.