.\" Man page generated from reStructuredText. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "PRINTF" "1" "Nov 13, 2025" "4.2" "fish-shell" .SH NAME printf \- display text according to a format string .SH SYNOPSIS .nf \fBprintf\fP \fIFORMAT\fP [\fIARGUMENT\fP \&...] .fi .sp .SH DESCRIPTION .sp NOTE: This page documents the fish builtin \fBprintf\fP\&. To see the documentation on any non\-fish versions, use \fBcommand man printf\fP\&. .sp \fBprintf\fP uses the format string \fIFORMAT\fP to print the \fIARGUMENT\fP arguments. This means that it takes format specifiers in the format string and replaces each with an argument. .sp The \fIFORMAT\fP argument is re\-used as many times as necessary to convert all of the given arguments. So \fBprintf %s\en flounder catfish clownfish shark\fP will print four lines. .sp Unlike \fI\%echo\fP, \fBprintf\fP does not append a new line unless it is specified as part of the string. .sp It doesn\(aqt support any options, so there is no need for a \fB\-\-\fP separator, which makes it easier to use for arbitrary input than \fBecho\fP\&. [1] .SH FORMAT SPECIFIERS .sp Valid format specifiers are taken from the C library function \fBprintf(3)\fP: .INDENT 0.0 .IP \(bu 2 \fB%d\fP or \fB%i\fP: Argument will be used as decimal integer (signed or unsigned) .IP \(bu 2 \fB%o\fP: An octal unsigned integer .IP \(bu 2 \fB%u\fP: An unsigned decimal integer \- this means negative numbers will wrap around .IP \(bu 2 \fB%x\fP or \fB%X\fP: An unsigned hexadecimal integer .IP \(bu 2 \fB%f\fP, \fB%g\fP or \fB%G\fP: A floating\-point number. \fB%f\fP defaults to 6 places after the decimal point (which is locale\-dependent \- e.g. in de_DE it will be a \fB,\fP). \fB%g\fP and \fB%G\fP will trim trailing zeroes and switch to scientific notation (like \fB%e\fP) if the numbers get small or large enough. .IP \(bu 2 \fB%e\fP or \fB%E\fP: A floating\-point number in scientific (XXXeYY) notation .IP \(bu 2 \fB%s\fP: A string .IP \(bu 2 \fB%b\fP: As a string, interpreting backslash escapes, except that octal escapes are of the form 0 or 0ooo. .UNINDENT .sp \fB%%\fP signifies a literal \(dq%\(dq. .sp Conversion can fail, e.g. \(dq102.234\(dq can\(aqt losslessly convert to an integer, causing printf to print an error. If you are okay with losing information, silence errors with \fB2>/dev/null\fP\&. .sp A number between the \fB%\fP and the format letter specifies the width. The result will be left\-padded with spaces. .SH BACKSLASH ESCAPES .sp printf also knows a number of backslash escapes: .INDENT 0.0 .IP \(bu 2 \fB\e\(dq\fP double quote .IP \(bu 2 \fB\e\e\fP backslash .IP \(bu 2 \fB\ea\fP alert (bell) .IP \(bu 2 \fB\eb\fP backspace .IP \(bu 2 \fB\ec\fP produce no further output .IP \(bu 2 \fB\ee\fP escape .IP \(bu 2 \fB\ef\fP form feed .IP \(bu 2 \fB\en\fP new line .IP \(bu 2 \fB\er\fP carriage return .IP \(bu 2 \fB\et\fP horizontal tab .IP \(bu 2 \fB\ev\fP vertical tab .IP \(bu 2 \fB\eooo\fP octal number (ooo is 1 to 3 digits) .IP \(bu 2 \fB\exhh\fP hexadecimal number (hhh is 1 to 2 digits) .IP \(bu 2 \fB\euhhhh\fP 16\-bit Unicode character (hhhh is 4 digits) .IP \(bu 2 \fB\eUhhhhhhhh\fP 32\-bit Unicode character (hhhhhhhh is 8 digits) .UNINDENT .SH ERRORS AND RETURN STATUS .sp If the given argument doesn\(aqt work for the given format (like when you try to convert a number like 3.141592 to an integer), printf prints an error, to stderr. printf will then also return non\-zero, but will still try to print as much as it can. .sp It will also return non\-zero if no argument at all was given, in which case it will print nothing. .sp This printf has been imported from the printf in GNU Coreutils version 6.9. If you would like to use a newer version of printf, for example the one shipped with your OS, try \fBcommand printf\fP\&. .SH EXAMPLE .INDENT 0.0 .INDENT 3.5 .sp .EX printf \(aq%s\et%s\en\(aq flounder fish .EE .UNINDENT .UNINDENT .sp Will print \(dqflounder fish\(dq (separated with a tab character), followed by a newline character. This is useful for writing completions, as fish expects completion scripts to output the option followed by the description, separated with a tab character. .INDENT 0.0 .INDENT 3.5 .sp .EX printf \(aq%s: %d\(aq \(dqNumber of bananas in my pocket\(dq 42 .EE .UNINDENT .UNINDENT .sp Will print \(dqNumber of bananas in my pocket: 42\(dq, \fIwithout\fP a newline. .SH SEE ALSO .INDENT 0.0 .IP \(bu 2 the \fI\%echo\fP command, for simpler output .UNINDENT .SH FOOTNOTES .IP [1] 5 In fact, while fish\(aqs \fBecho\fP supports \fB\-\-\fP, POSIX forbids it, so other implementations can\(aqt be used if the input contains anything starting with \fB\-\fP\&. .SH COPYRIGHT fish-shell developers .\" Generated by docutils manpage writer. .