#printf命令, format the output statement
#用于格式化输出, is the echo-enhanced version, a limited variant of the C-Language printf library function, with slightly different syntax
#是由POSIX标准所定义, the transplant is better than echo.
#printf不会像echo自动换行, so add \ n to break the line, as follows:
1 " This is a test \ n " 2 " OK? \ n "
#语法: printf format-string# Format Control string # [arguments# parameter list #]
#与C语言printf函数不同如下
# 1.printf command without parentheses
# 2.format-string can be without quotes, but preferably plus, single double quotes can be
# 3. Parameter extra format control (%), format-string can be reused, all parameters can be replaced
# 4.arguments using spaces to separate
#示例如下:
# format-string is double quotes, output 1 ABC
1 " %d%s \ n " 1 " ABC "
# single quotes and double quotes effect, output 1 abc\
1 ' %d%s \ n ' 1 " ABC "
# The format specifies only one parameter, but the extra parameter is still output in that format, format-string is reused
1 ' %s\n ' AAA BBB 2 ' %s%s%s \ n ' a b c d E F g
# If there is no arguments, then%s is replaced with null, and%d is replaced with 0. Output results: 0
1 ' %s and%d \ n '
The string is displayed in the format #如果以%d, and an invalid number is indicated, at which time the default value is 0. Output Result: Hello 0
1 " The first program always prints%s%d\n " Hello Shell
Linux Gvim Shell printf Command