diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-10-21 17:21:57 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-10-22 17:49:03 +0200 |
commit | 0341e3fde73aa44cb5b2b4037b969fa74a0ea369 (patch) | |
tree | 22ad5cf868fd0aea2bc81372cab9fa3075f13eea /Base/usr/share | |
parent | 5b72d17ff642c8d5d20bc1487466c13ebd6cfb45 (diff) | |
download | serenity-0341e3fde73aa44cb5b2b4037b969fa74a0ea369.zip |
Base: Add a manpage for 'printf'
Diffstat (limited to 'Base/usr/share')
-rw-r--r-- | Base/usr/share/man/man1/printf.md | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Base/usr/share/man/man1/printf.md b/Base/usr/share/man/man1/printf.md new file mode 100644 index 0000000000..abf5cd466d --- /dev/null +++ b/Base/usr/share/man/man1/printf.md @@ -0,0 +1,53 @@ +## Name + +printf - format and print data + +## Synopsis + +```**sh +printf <format> [arguments...] +``` + +## Description + +`printf` formats _argument_(s) according to _format_ and prints the result to standard output. + +_format_ is similar to the C printf format string, with the following differences: +- The format specifier `b` (`%b`) is not supported. +- The format specifiers that require a writable pointer (e.g. `n`) are not supported. +- The format specifier `q` (`%q`) has a different behaviour, where it shall print a given string as a quoted string, which is safe to use in shell inputs. +- Common escape sequences are interpreted, namely the following: + +| escape | description | +| :-: | :--- | +| `\\\\`| literal backslash | +| `\\"` | literal double quote | +| `\\a` | alert (BEL) | +| `\\b` | backspace | +| `\\c` | Ends the format string | +| `\\e` | escape (`\\x1b`) | +| `\\f` | form feed | +| `\\n` | newline | +| `\\r` | carriage return | +| `\\t` | tab | +| `\\v` | vertical tab | + + +The _format_ string is reapplied until all arguments are consumed, and a missing argument is treated as zero for numeric format specifiers, and an empty string for string format specifiers. + +## Examples + +```sh +# print 64 as a hexadecimal number, with the starting '0x' +$ printf '%#x' 64 + +# prints "a0\n", ignoring everything after '\c' +$ printf '%s%d\n\caaaa' a + +# prints "123400", as 'x' is an invalid number, and the missing argument for the last '%d' is treated as zero. +$ printf '%d%d%d' 1 2 3 4 x +``` + +## See also + +* [`echo`(1)](../man1/echo.md) |