zoukankan      html  css  js  c++  java
  • shell之echo and printf

    #!/bin/sh

    _________echo___________
    #read name
    #echo "$name It is a test" #read命令从标准的输入中读取一行,并把输入方的每个字段的值指定给shell变量
    #echo "OK! "
    #echo -e "OK! " # -e 开启转义
    #echo -e "ok! "
    #echo "It is a test !!!" > myfile
    #echo `date`
    #read firststr secondstr
    #echo "第一个参数:$firststr;第二个参数:$secondstr"
    read -p "请输入一段文字:" -n 6 -s password
    echo -e " password is $password"
    #-p 输入提示文字
    #-n 输入字符长度限制(达到6位,自动结束)
    # -t 输入限时
    #-s 输入隐藏内容

    __________printf__________

    #!/bin/sh
    #printf 也是一个shell输出命令命令模仿c程序库(library)里的printf()程序,移植性比echo好,语法:printf format-string [arguments...],参数一:格式控制的字符串,参数二:参数列表
    #printf 'hello,shell '
    #printf "%-10s %-8s %-4s " 姓名 性别 体重KG
    #printf "%-10s %-8s %-4s " 郭靖 男 66.1234
    #printf "%-10s %-8s %-4s " 杨过 男 48.6543
    #printf "%-10s %-8s %-4s " 郭芙 女 47.9876
    #%s %c %d %f 都是格式替代符
    #%d Decimal 十进制整数 -- 对应位置参数必须是十进制整数,否则报错
    #%s String 字符串 -- 对应位置参数必须是字符串或者字符型,否则报错!
    #%c: Char 字符 -- 对应位置参数必须是字符串或者字符型,否则报错!
    #%f: Float 浮点 -- 对应位置参数必须是数字型,否则报错
    #printf "%d %s " 1 "abc"
    #printf '%d %s ' 1 "abc" #单引号与双引号的输出效果一致
    #printf %s hello,world! #没有引号也可以输出
    #printf %s hello world #只制定了一个参数,但多出的参数仍然会按照该格式输出,format-string被重用
    # printf "%s " hello world
    # printf "%s %s %s " a b c d e f g h i j
    # printf '%s and %d ' #如果没有arguments,那么%s用null代替,%d用0代替
    # #转义序列:
    # a 警告字符
    #  后退
    # c 抑制(不显示)输出结果中任何结尾的换行字符(只在%b格式指示符控制下的参数字符串中有效)
    # f 换页(formfeed)
    # 换行
    # 回车(Carriage return)
    # 水平制表符
    # v 垂直制表符
    # \ 一个字面上的反斜杠字符
    # ddd 表示1到3位数八进制值的字符。仅在格式字符串中有效
    # ddd 表示1到3位的八进制值字符
    printf '%s and %d and %c and %4.4f ' '1+1=' 2 'True' 12323.1415

    资源来自:http://www.runoob.com/

    脑子不够用当然只能脚踏实地的做事情!
  • 相关阅读:
    ElasticSearch Java API 增删改查操作
    ElasticSearch Java API连接报错NoNodeAvailableException解决方案
    Elasticsearch 使用Kibana实现基本的增删改查+mget批量查询+bulk批量操作
    Elasticsearch CentOS6.5下安装ElasticSearch6.2.4+elasticsearch-head+Kibana
    Elasticsearch 核心概念:NRT+索引+分片+副本
    Solr solrj4与solrj-7.7.2操作solrcloud
    Solr Centos6.5下搭建solr-7.7.2集群solrcloud+DIH操作
    分层图【p2939】[USACO09FEB]改造路Revamping Trails
    NOIP2018提高组模拟题(二)
    树链剖分【p3178】[HAOI2015]树上操作
  • 原文地址:https://www.cnblogs.com/qtclm/p/10314511.html
Copyright © 2011-2022 走看看