Reference documents:
There are eight ways to intercept a string, mainly for the following methods
650) this.width=650; "alt=" Copy Code "src=" Http://common.cnblogs.com/images/copycode.gif "/>
There are a number of ways to intercept strings in the shell, ${expression} There are 9 ways to use them. ${parameter:-word}${parameter:=word}${parameter:?word}${parameter:+word} above 4 alternatives that can be used for default values. ${#parameter} This can get the length of the string. ${parameter%word} minimal intercept from behind word${parameter%%word} maximum intercept from the back word${parameter#word} Minimal interception of word${parameter# from the front #word} maximum from the front to intercept word above 4 is the way to intercept the string. With four usages, you don't have to use the cut command to intercept a string. The first type can be divided into four cases, described below. 1. Use the # operator. The purpose is to delete the first occurrence of the substring, the left character, and the right character, starting from the left. Usage is #*substr, for example: Str= ' http://www. your domain name. com/cut-string.html ' echo ${str#*//} results from www. your domain name. com/ cut-string.html, i.e. delete all characters 2 from the left to the first "//" and its left, using the ## operator. The purpose is to delete the last occurrence of the substring, which is the left character, from the left side, leaving the right character. Usage is ##*substr, for example: Str= ' http://www. your domain name. com/cut-string.html ' echo ${str##*/} results in cut-string.html, that is, delete the last occurrence of "/" And its left all characters 3, use the % operator. The purpose is to delete the first occurrence of the substring, the right character, and the left character, starting from the right. The usage is%substr*, for example: Str= ' http://www. your domain name. com/cut-string.html ' echo ${str%/*} results are/HTTP// www. your domain name. com, that is, delete all characters from the right to the first "/" and the right of the 4, using the %% operator. The purpose is to delete the last occurrence of the substring, which is the right character, from the right, leaving the left character. Usage is%%substr*, for example: str=' http://www. your domain name. com/cut-string.html ' echo ${str%%/*} results in http://www. your domain name. com, i.e. delete from right to last "/" And its right all characters the second kind is divided into four kinds, respectively, the following: 1, starting from the left of the first few characters and the number of characters, using: Start:len, for example: Str= ' http://www. your domain name. com/cut-string.html ' Echo ${var:0:5} where the 0 represents the first character on the left,,5 represents the total number of characters. The result is: Http:2, starting from the first few characters on the left until the end, using: Start, for example: Str= ' http://www. your domain name. com/cut-string.html ' Echo ${var:7} where 7 represents the 8th character on the left. The result is: www. your domain name. COM/CUT-STRING.HTML3, starting with the first few characters on the right and the number of characters, usage: 0-start:len, for example: str= '/http www. your domain name. com/cut-string.html ' Echo ${str:0-15:10} where the 0-6 represents the right side of the 6th character start,10 represents the number of characters. The result is: Cut-string3, starting from the first few characters on the right to the end, usage: 0-start, for example: Str= ' http://www. your domain name. com/cut-string.html ' Echo ${str:0-4} where the 0-6 indicates the right side of the 6th character starting,10 represents the number of characters. The result is: HTML Note: (the first character on the left is denoted by 0 , the first character on the right is represented by 0-1 )
650) this.width=650; "alt=" Copy Code "src=" Http://common.cnblogs.com/images/copycode.gif "/>
This article is from the "Healer" blog, make sure to keep this source http://zlyang.blog.51cto.com/1196234/1710899
Summary of Shell interception string methods in Linux