|
此文章由 nali 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 nali 所有!转贴必须注明作者、出处和本声明,并保持内容完整
Advanced Bash-Scripting Guide 第780页和 第125页
http://www.tldp.org/LDP/abs/abs-guide.pdf
${string:position:length}
Extract $length characters substring from $string at $position [zero-indexed, first character is at position 0]- Table B-5. String Operations
- Expression Meaning
- ${#string} Length of $string
- ${string:position} Extract substring from $string at $position
- ${string:position:length} Extract $length characters substring from $string at $position [zero-indexed, first character is at position 0]
- ${string#substring} Strip shortest match of $substring from front of $string
- ${string##substring} Strip longest match of $substring from front of $string
- ${string%substring} Strip shortest match of $substring from back of $string
- ${string%%substring} Strip longest match of $substring from back of $string
- ${string/substring/replacement} Replace first match of $substring with $replacement
- ${string//substring/replacement} Replace all matches of $substring with $replacement
- ${string/#substring/replacement} If $substring matches front end of $string, substitute $replacement for $substring
- ${string/%substring/replacement} If $substring matches back end of $string, substitute $replacement for $substring expr match "$string" '$substring' Length of matching $substring* at beginning of $string
复制代码 |
|