zoukankan      html  css  js  c++  java
  • 变量替换测试

    变量替换测试

    语法 说明
    ${变量名#匹配规则} 从变量开头进行规则匹配,将符合最短的数据删除
    ${变量名##匹配规则} 从变量开头进行规则匹配,将符合最长的数据删除
    ${变量名%匹配规则} 从变量尾部进行规则匹配,将符合最短的数据删除
    ${变量名%匹配规则} 从变量尾部进行规则匹配,将符合最长的数据删除
    ${变量名/旧字符串/新字符串} 变量内容符合旧字符串则,第一个旧字符串会被新字符串取代
    ${变量名//旧字符串/新字符串} 变量内容符合旧字符串则,全部的旧字符串会被新字符串取代
    [master@instance-2m5iiamd ~]$ variable="Linux is very funny! Yes, it is."
    [master@instance-2m5iiamd ~]$ echo $variable 
    Linux is very funny! Yes, it is.
    [master@instance-2m5iiamd ~]$ variable1=${variable#*is}
    [master@instance-2m5iiamd ~]$ echo $variable
    Linux is very funny! Yes, it is.
    [master@instance-2m5iiamd ~]$ echo $variable1
    very funny! Yes, it is.
    [master@instance-2m5iiamd ~]$ variable2=${variable##*is}
    [master@instance-2m5iiamd ~]$ echo $variable2
    .
    [master@instance-2m5iiamd ~]$ variable3=${variable%is}
    [master@instance-2m5iiamd ~]$ echo $variable3
    Linux is very funny! Yes, it is.
    [master@instance-2m5iiamd ~]$ variable3=${variable%is*}
    [master@instance-2m5iiamd ~]$ echo $variable3
    Linux is very funny! Yes, it
    [master@instance-2m5iiamd ~]$ variable4=${variable%%is*}
    [master@instance-2m5iiamd ~]$ echo $variable4
    Linux          
    [master@instance-2m5iiamd ~]$ echo $PATH 
    /usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/master/.local/bin:/home/master/bin
    [master@instance-2m5iiamd ~]$ variable4=${PATH/bin/BIN} 
    [master@instance-2m5iiamd ~]$ echo $variable4
    /usr/local/BIN:/usr/bin:/usr/local/sbin:/usr/sbin:/home/master/.local/bin:/home/master/bin
    [master@instance-2m5iiamd ~]$ variable5=${PATH//bin/BIN} 
    [master@instance-2m5iiamd ~]$ echo $variable5
    /usr/local/BIN:/usr/BIN:/usr/local/sBIN:/usr/sBIN:/home/master/.local/BIN:/home/master/BIN
    [master@instance-2m5iiamd ~]$ 
    
  • 相关阅读:
    SNIMissingWarning,InsecurePlatformWarning 以及 GotoBLAS : Architecture Initialization failed. No initialization function found.
    python-获取上个月全部周几
    Springboot-Jpa多数据库配置-2.0+版本
    springboot通过JdbcTemplate实现多数据库
    使用cuteftp实现SFTP上传
    Jar后台运行脚本 window-bat/unix-sh for springboot
    Invalid control character at: line 1 column 解决
    QTP常用function 老古董
    NoClassDefFoundError: javax/xml/bind/JAXBException-springboot
    MySQL
  • 原文地址:https://www.cnblogs.com/linga/p/10967977.html
Copyright © 2011-2022 走看看