printf
Content formatted output
format
printf [format] [typing]
format parameters
% b: the print content and explain where the backslash ' \ "special characters % Q: print content references format shell, so that it can be reused in the standard input % D: in signed decimal format print content % i: the% D identical % O: print content unsigned octal % U: print content unsigned decimal format % X: unsigned lowercase hexadecimal print content % X-: unsigned uppercase hexadecimal print content % F: floating-point format and parsed to print content % E: the print content to double precision floating point format % E: the% E identical, except uppercase letters % g: in% or f% e format print content % G: in% f% or print format content e % C: print content format characters, and only the print parameters in the first character % S: string format Print content % the n-: Specifies the number of characters printed %%: Indicates that the print character " % "
escape character format
\ " Print " symbol \ NNN indicates an ASCII character with octal values \\ print \ symbol \ a warning sound before \ b to delete a character \ f formfeed, in some implementations will clear the screen, some will wrap \ n newline \ r does not wrap, the cursor is at the first \ t tab \ v vertical tab \ xhh ASCII characters represent a hexadecimal value
Examples
# Print shell characters, and wrap printf " % S \ the n- " shell # print the full length of shell characters, and wrap printf " % 1S \ the n- " shell # print left shell characters first character, and wrap printf " % 1.1s \ the n- " shell # print left shell start of the first to third character (if specified character longer than the actual length, with spaces to complement the excess part), and wrap printf " % 5.2s \ the n- " shell # to float the print type printing characters printf " % 6.2f \ the n- " 123.45678