1. String Truncation
(1) intercept the string before and after a specified character
[Root @ gd86 applications] # Var = Hello: zkl: zyh
[Root @ gd86 applications] # echo $ {var %: *} returns the first string from right to left.
Hello: zkl
[Root @ gd86 applications] # echo $ {var %: *} returns the last string from the right to the left.
Hello
[Root @ gd86 applications] # echo $ {var # *:} count from left to right and capture the last string:
Zyh
[Root @ gd86 applications] # echo $ {var # *:} returns the first string after the first string.
Zkl: zyh
(2) truncate a string at the specified start position and length
[Root @ gd86 applications] # echo $ {var: 0: 5} intercepts a string starting from string 0 with a length of 5
Hello
Or
Expr substr $ var 1 2 truncates a string starting from position 1 with a length of 2. The first string position is 1. Note that
For example:
[Root @ gd86 applications] # echo $ VaR
Hello: zkl: zyh: ABC
[Root @ gd86 applications] # expr substr $ var 1 2
He
2. String Truncation
Var = $ Var "$ Var" to complete string connection
3. traverse the substrings of strings separated by Spaces
For sub in $ strings
Do
Echo $ sub
Done