Shell变​量​子​串​演示

    Read

${#parameter}:返回$parameter的长度;


${parameter:offset}:在$parameter中,从位置offset之后开始提取子串;

${parameter:offset:length}:在$parameter中从位置offset之后开始提取长度为length子串;

${parameter#word}:从变量$parameter开头开始删除最短匹配word子串;

${parameter##word}:从变量$parameter开头开始删除最长匹配word子串;

${parameter%word}:从变量$parameter结尾开始删除最短匹配word子串;

${parameter%%word}:从变量$parameter结尾开始删除最长匹配word子串;

${parameter/pattern/string}:使用string,来代替第一个匹配的word;

${parameter/#pattern/string}:如果$parameter前缀匹配word,就用string来代替匹配word;

${parameter/%pattern/string}:如果$parameter后缀匹配word,就用string来代替匹配word;

案例:取消_finished

参考资料:

参考:http://wenku.baidu.com/view/f4182920482fb4daa58d4b40?fr=prin

申明:本文由BYRD原创(基于Centos6.4 X64),未经许可禁止转载!SourceByrd's Weblog-https://note.t4x.org/system/shell-variable-substring/ SourceByrd's Weblog-https://note.t4x.org/system/shell-variable-substring/

申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!
Byrd
  • by Published on July 22, 2014
  • 原文链接:https://note.t4x.org/system/shell-variable-substring/
匿名

Comment

Anonymous

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: