printf - format and print data

Name    
        printf - format and print data 


Synopsis
        printf FORMAT [ARGUMENT]... 
        printf OPTION


Description
        Print ARGUMENT(S) according to FORMAT, or execute according \
        to OPTION
   
        --help      : display this help and exit


        --version   : output version infomation and exit


        FORMAT controls the output as in C printf. Interpreted  \
        sequences are:
        \"      : double quote(双引号)
        \\      : backslash(反斜线)
        \a      : alert(BEL)(警告声输出)
        \b      : backspace(倒退键)
        \c      : produce no further output(在此处停止输出, 与%b配合)
        \f      : form feed(进纸键)
        \n      : new line(输出新一行)
        \r      : carriage return(回车)
        \v      : horizontal tab(水平TAB键) 
        \t      : vertical tab(垂直TAB键)
        \NNN    : byte with octal value NNN(1 to 3 digits)
                (NN为数字, 可以转换数字为字节
        \xNN    : byte with hexadecimal value HH(1 to 2 digits)
        \uHHHH  : Unicode (ISO/IEC 10646) character with hex value \
                  HHHH(4 digits)
        %%      : a single %
        %b      : ARGUMENT as a string with '\' escapes interpreted, \
                  except that octal escapes are of the form \0 or \0NNN
                  (把输出字符串里的带\的字符当做转义字符)
        %p      : 在单词词尾添加\, 最后一个字符例外.


       controls string : %d, %i, %I, %u, %x, %X, %e, %E, %f, %g, %s
       controls flags : -, 0, +, #, ' '


       and all C format specifications ending with one of diouxXfeEgGcs, \
       with ARGUMENTs converted to proper type first. Variable widths    \
       are handled.


       NOTE: your shell may have its own version of printf, which usually \
       supersedes the version described here. Press refer to your shell's \
       documentation for details about the options it supports.


        %ns : n为数字, s为字符串, 串起来表示n个字节.
        %ni : n为数字, i为整数, 串起来表示n个数字
        %n.mf : n,m为数字, f为浮点数, 串起来就是n个数字     


示例:
    printf "%10s\t%5i\t%5i\t%5i\t%8.2f" $(cat printf.txt)
        把printf.txt的数据打印出来
    printf "123%b" "\n456"
        打印: 123 换行 456
    printf "123%s" "\n456"
        打印: 123\n456
    printf "\033[31mHello, World!\033[0m\n";
        打印字符串"Hello, World!",并设置为红色


说明:
. 如果格式需要的参数比后面给出的多,超出的部分为0或者null。
. 格式化格式: %flags width.precision format-specifier
. printf可以控制输出字符串的颜色或者高亮等属性.


-------------------------------------------------------------------
终端的字符颜色用转义序列控制,是文本模式下的系统显示功能。转义序列是以 \
ESC开头,可以用\033完成相同的工作(ESC的ASCII码用八进制表示为33)。


格式:
\033[显示方式;前景色;背景色m


前景色:
    30(黑色)、31(红色)、32(绿色)、 33(黄色)、34(蓝色)、\
    35(洋红)、36(青色)、37(白色)
背景色:
    40(黑色)、41(红色)、42(绿色)、 43(黄色)、44(蓝色)、\
    45(洋红)、46(青色)、47(白色)


显示方式:
    /033[0m   关闭所有属性  
    /033[1m   设置高亮度  
    /03[4m   下划线  
    /033[5m   闪烁  
    /033[7m   反显  
    /033[8m   消隐  
    /033[30m   --   /033[37m   设置前景色  
    /033[40m   --   /033[47m   设置背景色  
    /033[nA   光标上移n行  
    /03[nB   光标下移n行  
    /033[nC   光标右移n行  
    /033[nD   光标左移n行  
    /033[y;xH设置光标位置  
    /033[2J   清屏  
    /033[K   清除从光标到行尾的内容  
    /033[s   保存光标位置  
    /033[u   恢复光标位置  
    /033[?25l   隐藏光标  
    /33[?25h   显示光标

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值