• 变量替换测试


    变量替换测试

    语法 说明
    ${变量名#匹配规则} 从变量开头进行规则匹配,将符合最短的数据删除
    ${变量名##匹配规则} 从变量开头进行规则匹配,将符合最长的数据删除
    ${变量名%匹配规则} 从变量尾部进行规则匹配,将符合最短的数据删除
    ${变量名%匹配规则} 从变量尾部进行规则匹配,将符合最长的数据删除
    ${变量名/旧字符串/新字符串} 变量内容符合旧字符串则,第一个旧字符串会被新字符串取代
    ${变量名//旧字符串/新字符串} 变量内容符合旧字符串则,全部的旧字符串会被新字符串取代
    [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 ~]$ 
    
  • 相关阅读:
    JavaScript 判断 URL
    AppCan 文件上传实例
    IIS6.0手动安装与配置asp.net2.0全过程
    轻松搭建一个Windows SVN服务器
    IIS6.0上某些文件类型不能下载
    JavaScript 数组转字符串,字符串转数组
    百度地图API 应用实例
    IIS7.5 下:HTTP 错误 404.17 Not Found 请求的内容似乎是脚本 解决方法
    SQL 交集 差集 并集 笛卡尔积 应用实例
    Win7 64位 IIS未能加载文件或程序集“System.Data.SQLite”或它的某一个依赖项
  • 原文地址:https://www.cnblogs.com/linga/p/10967977.html
Copyright © 2020-2023  润新知