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 
    "
  • 相关阅读:
    apache虚拟主机三种不同配置方式
    搭建http服务器及配置
    学校ftp服务器搭建
    vsftpd搭建使用
    nginx使用
    pxe+kickafkstart (二)转
    pxe批量网络装机
    bash中()使用特性
    ansible使用
    javascript 之 Object.defineProperty
  • 原文地址:https://www.cnblogs.com/gyjx2016/p/13565569.html
Copyright © 2011-2022 走看看