{
    "content": [
        {
            "type": "text",
            "text": "# printf (info)\n\n## Sections\n\n- **File: coreutils.info,  Node: printf invocation,  Next: yes invocation,  Prev: echo invocation,  Up: Printing text** (1 subsections)\n- **Unicode characters according to the 'LCCTYPE' locale.  Unicode**\n- **Here is how to convert a piece of text into a shell script which will**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "printf",
        "section": "",
        "mode": "info",
        "summary": null,
        "synopsis": null,
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "File: coreutils.info,  Node: printf invocation,  Next: yes invocation,  Prev: echo invocation,  Up: Printing text",
                "lines": 1,
                "subsections": [
                    {
                        "name": "15.2 'printf': Format and print data",
                        "lines": 72
                    }
                ]
            },
            {
                "name": "Unicode characters according to the 'LCCTYPE' locale.  Unicode",
                "lines": 31,
                "subsections": []
            },
            {
                "name": "Here is how to convert a piece of text into a shell script which will",
                "lines": 14,
                "subsections": []
            }
        ],
        "sections": {
            "File: coreutils.info,  Node: printf invocation,  Next: yes invocation,  Prev: echo invocation,  Up: Printing text": {
                "content": "",
                "subsections": [
                    {
                        "name": "15.2 'printf': Format and print data",
                        "content": "'printf' does formatted printing of text.  Synopsis:\n\nprintf FORMAT [ARGUMENT]...\n\n'printf' prints the FORMAT string, interpreting '%' directives and\n'\\' escapes to format numeric and string arguments in a way that is\nmostly similar to the C 'printf' function.  *Note 'printf' format\ndirectives: (libc)Output Conversion Syntax, for details.  The\ndifferences are listed below.\n\nDue to shell aliases and built-in 'printf' functions, using an\nunadorned 'printf' interactively or in a script may get you different\nfunctionality than that described here.  Invoke it via 'env' (i.e., 'env\nprintf ...') to avoid interference from the shell.\n\n* The FORMAT argument is reused as necessary to convert all the given\nARGUMENTs.  For example, the command 'printf %s a b' outputs 'ab'.\n\n* Missing ARGUMENTs are treated as null strings or as zeros,\ndepending on whether the context expects a string or a number.  For\nexample, the command 'printf %sx%d' prints 'x0'.\n\n* An additional escape, '\\c', causes 'printf' to produce no further\noutput.  For example, the command 'printf 'A%sC\\cD%sF' B E' prints\n'ABC'.\n\n* The hexadecimal escape sequence '\\xHH' has at most two digits, as\nopposed to C where it can have an unlimited number of digits.  For\nexample, the command 'printf '\\x07e'' prints two bytes, whereas the\nC statement 'printf (\"\\x07e\")' prints just one.\n\n* An additional directive '%b', prints its argument string with '\\'\nescapes interpreted in the same way as in the FORMAT string, except\nthat octal escapes are of the form '\\0OOO' where OOO is 0 to 3\noctal digits.  If '\\OOO' is nine-bit value, ignore the ninth bit.\nIf a precision is also given, it limits the number of bytes printed\nfrom the converted string.\n\n* An additional directive '%q', prints its argument string in a\nformat that can be reused as input by most shells.  Non-printable\ncharacters are escaped with the POSIX proposed '$''' syntax, and\nshell metacharacters are quoted appropriately.  This is an\nequivalent format to 'ls --quoting=shell-escape' output.\n\n* Numeric arguments must be single C constants, possibly with leading\n'+' or '-'.  For example, 'printf %.4d -3' outputs '-0003'.\n\n* If the leading character of a numeric argument is '\"' or ''' then\nits value is the numeric value of the immediately following\ncharacter.  Any remaining characters are silently ignored if the\n'POSIXLYCORRECT' environment variable is set; otherwise, a warning\nis printed.  For example, 'printf \"%d\" \"'a\"' outputs '97' on hosts\nthat use the ASCII character set, since 'a' has the numeric value\n97 in ASCII.\n\nA floating point argument is interpreted according to the\n'LCNUMERIC' category of either the current or the C locale, and is\nprinted according to the current locale.  For example, in a locale whose\ndecimal point character is a comma, the command 'printf '%g %g' 2,5 2.5'\noutputs '2,5 2,5'.  *Note Floating point::.\n\n'printf' interprets '\\OOO' in FORMAT as an octal number (if OOO is 1\nto 3 octal digits) specifying a byte to print, and '\\xHH' as a\nhexadecimal number (if HH is 1 to 2 hex digits) specifying a character\nto print.  Note however that when '\\OOO' specifies a number larger than\n255, 'printf' ignores the ninth bit.  For example, 'printf '\\400'' is\nequivalent to 'printf '\\0''.\n\n'printf' interprets two syntax forms for specifying Unicode (ISO/IEC\n10646) characters.  '\\u' for 16-bit Unicode characters, specified as\nfour hexadecimal digits HHHH, and '\\U' for 32-bit Unicode characters,\nspecified as eight hexadecimal digits HHHHHHHH.  'printf' outputs the"
                    }
                ]
            },
            "Unicode characters according to the 'LCCTYPE' locale.  Unicode": {
                "content": "characters in the range U+D800...U+DFFF cannot be specified by this\nsyntax.  This syntax fully supports the universal character subset\nintroduced in ISO C 99.\n\nThe processing of '\\u' and '\\U' requires a full-featured 'iconv'\nfacility.  It is activated on systems with glibc 2.2 (or newer), or when\n'libiconv' is installed prior to this package.  Otherwise '\\u' and '\\U'\nwill print as-is.\n\nUnicode character syntax is useful for writing strings in a locale\nindependent way.  For example, a string containing the Euro currency\nsymbol\n\n$ env printf '\\u20AC 14.95'\n\nwill be output correctly in all locales supporting the Euro symbol\n(ISO-8859-15, UTF-8, and others).  Similarly, a Chinese string\n\n$ env printf '\\u4e2d\\u6587'\n\nwill be output correctly in all Chinese locales (GB2312, BIG5, UTF-8,\netc).\n\nNote that in these examples, the 'printf' command has been invoked\nvia 'env' to ensure that we run the program found via your shell's\nsearch path, and not a shell alias or a built-in function.\n\nFor larger strings, you don't need to look up the hexadecimal code\nvalues of each character one by one.  ASCII characters mixed with \\u\nescape sequences is also known as the JAVA source file encoding.  You\ncan use GNU recode 3.5c (or newer) to convert strings to this encoding.",
                "subsections": []
            },
            "Here is how to convert a piece of text into a shell script which will": {
                "content": "output this text in a locale-independent way:\n\n$ LCCTYPE=zhTW.big5 env printf \\\n'\\u4e2d\\u6587\\n' > sample.txt\n$ recode BIG5..JAVA < sample.txt \\\n| sed -e \"s|^|env printf '|\" -e \"s|%|%%|g\" -e \"s|$|\\\\\\\\n'|\" \\\n> sample.sh\n\nThe only options are a lone '--help' or '--version'.  *Note Common\noptions::.  Options must precede operands.\n\nAn exit status of zero indicates success, and a nonzero value\nindicates failure.\n",
                "subsections": []
            }
        }
    }
}