zoukankan      html  css  js  c++  java
  • 【shell】printf

    #!/bin/bash
    #shell printf
    
    printf "%-10s %-8s %-4s
    " 姓名 性别 体重kg  
    printf "%-10s %-8s %-4.2f
    " 郭靖 男 66.1234 
    printf "%-10s %-8s %-4.2f
    " 杨过 男 48.6543 
    printf "%-10s %-8s %-4.3f
    " 郭芙 女 47.9876 
    
    # %s %c %d %f都是格式替代符
    # %-10s 指一个宽度为10个字符(-表示左对齐,没有则表示右对齐),任何字符都会被显示在10个字符宽的字符内,如果不足则自动以空格填充,超过也会将内容全部显示出来。
    # %-4.2f 指格式化为小数,其中.2指保留2位小数。
    
    
    # format-string为双引号
    printf "%d %s
    " 1 "abc"
    
    # 单引号与双引号效果一样 
    printf '%d %s
    ' 1 "abc" 
    
    # 没有引号也可以输出
    printf %s abcdef 
    
    # 格式只指定了一个参数,但多出的参数仍然会按照该格式输出,format-string 被重用
    printf %s abc def 
    
    printf "%s
    " abc def
    
    printf "%s %s %s
    " a b c d e f g h i j
    
    # 如果没有 arguments,那么 %s 用NULL代替,%d 用 0 代替
    printf "%s and %d 
    "
  • 相关阅读:
    选择排序
    散列冲突解决方案
    string stringbuffer StringBuilder
    java关键字
    Vector
    What is the difference between book depreciation and tax depreciation?
    Type of Asset Books in Oracle Fixed Assets
    questions
    Oracle Express 11g
    iot
  • 原文地址:https://www.cnblogs.com/gyjx2016/p/13565569.html
Copyright © 2011-2022 走看看