Let’s say we have a variable var=www.aaa.com/123.htm.

1. # interception, delete characters on the left and retain characters on the right.

The copy code is as follows:


echo ${var#*//}

Where var is the variable name, # is the operator, *// indicates that the first // sign and all characters on the left are deleted from the left, i.e. http:// is deleted. The result is www.aaa.com/123.htm

2. ## interception, delete the left character, retain the right character.

The copy code is as follows:


echo ${var##*/}

##*/ indicates that the last (rightmost)/sign and all characters on the left are deleted from www.aaa.com/

The result is 123. HTM

3. % interception, delete the right character, retain the left character

The copy code is as follows:


echo ${var%/*}

%/* deletes the first/sign and the character on the right starting from the right

The result: www.aaa.com

4. %% number interception, delete the right character, retain the left character

The copy code is as follows:


echo ${var%%/*}

% % / *