zoukankan      html  css  js  c++  java
  • 变量内容的删除替换和替代

    (1)变量的删除

    [root@localhost scripts]# url=www.baidu.com.cn
    [root@localhost scripts]# echo ${#url}     获取变量的长度
    16
    [root@localhost scripts]# echo ${url}       标准查看
    www.baidu.com.cn
    [root@localhost scripts]# echo ${url#*.}    从前往后,最短匹配
    baidu.com.cn
    [root@localhost scripts]# echo ${url##*.}   从前往后,最长匹配,贪婪匹配
    cn
    [root@localhost scripts]# url=www.baidu.com.cn
    [root@localhost scripts]# echo ${url%.*}        从后往前,最短匹配
    www.baidu.com
    [root@localhost scripts]# echo ${url%%.*}       从后往前,最长匹配,贪婪匹配
    www

    (2)变量索引切片

    [root@localhost scripts]# url=www.baidu.com.cn
    [root@localhost scripts]# echo ${url:0:5}
    www.b
    [root@localhost scripts]# echo ${url:5:5}
    aidu.
    [root@localhost scripts]# echo ${url:5}
    aidu.com.cn

    (3)变量内容的替换

    [root@localhost scripts]# url=www.baidu.com.cn
    [root@localhost scripts]# echo ${url/baidu/sina}
    www.sina.com.cn
    [root@localhost scripts]# echo ${url//w/N}      贪婪匹配
    NNN.baidu.com.cn

    (4)变量的替代

    ${变量名-新的变量值}
    变量没有被赋值:会使用"新的变量值"替代
    变量有被赋值(包括空值):不会被替代
     
  • 相关阅读:
    C平衡二叉树(AVL)创建和删除
    C格式字符串转为二叉树
    C前序遍历二叉树Morris Traversal算法
    C单链表操作
    C仿黑白棋版XO棋
    C传递参数给main函数
    C图形化第一步
    Perl看完这个,再不敢说自己会玩贪吃蛇
    Perl寻路A*算法实现
    C字符贪吃蛇
  • 原文地址:https://www.cnblogs.com/li33232/p/12291880.html
Copyright © 2011-2022 走看看