In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
There are many ways to intercept strings in shell.
There are 9 ways to use ${expression}.
${parameter:-word}
${parameter:=word}
${parameter:?word}
${parameter:+word}
The above four can be used to replace the default values.
${# parameter}
The above allows you to get the length of the string.
${parameter%word} minimally intercept word from behind
${parameter%%word} maximum interception of word from behind
${parameter#word} minimally intercept word from the front
${parameter##word} maximize the interception of word from the front
The above four are the methods used to intercept strings.
With four uses, you don't have to use the cut command to intercept strings.
The first can be divided into four situations, which are described below.
1. Use the # operator. The purpose is to delete the first occurrence of the substring from the left, that is, its left character, and retain the right character. The usage is # * substr, for example:
Str=' http://www. your domain name .com / cut-string.html'
Echo ${str#*//}
The result obtained is www. Your domain name .com / cut-string.html, that is, delete all characters 2 from the left to the first "/ /" and to the left, using the # # operator. The purpose is to delete the last occurrence of the substring from the left, that is, its left character, and retain the right character. The usage is # # * substr, for example:
Str=' http://www. your domain name .com / cut-string.html'
Echo ${str##*/}
The result is cut-string.html, which deletes the last "/" and all its left characters
3. Use the% operator. The purpose is to delete the first occurrence of the substring from the right, that is, its right character, and retain the left character. Usage is% substr*, for example:
Str=' http://www. your domain name .com / cut-string.html'
Echo ${str%/*}
The result is http://www.. Your domain name .com, that is, delete all characters from the right to the first "/" and to the right
4. Use the%% operator. The purpose is to delete the last occurrence of the substring, that is, the character on the right, from the right, leaving the character on the left. Usage is%% substr*, for example:
Str=' http://www. your domain name .com / cut-string.html'
Echo ${str%%/*}
The result is http://www.. Your domain name .com, that is, delete all characters from the right to the last "/" and to the right
The second is also divided into four categories, which are introduced as follows:
1. Start with the character on the left and the number of characters, the usage is: start:len, for example:
Str=' http://www. your domain name .com / cut-string.html'
Echo ${var:0:5}
Where 0 indicates the beginning of the first character on the left, and 5 represents the total number of characters.
The result is: http:
2. From the first character on the left to the end, the usage is: start, for example:
Str=' http://www. your domain name .com / cut-string.html'
Echo ${var:7}
Seven of them indicates the beginning of the eighth character on the left.
The result is: www. Your domain name .com / cut-string.html
3. Start with the number of 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}
The 0-6 represents the sixth character on the right, and 10 represents the number of characters.
The result is: cut-string
3. From the beginning to the end of the character on the right, usage: 0-start, for example:
Str=' http://www. your domain name .com / cut-string.html'
Echo ${str:0-4}
The 0-6 represents the sixth character on the right, and 10 represents the number of characters.
The result is: html
Note: (the first character on the left is represented by 0, and the first character on the right is represented by 0-1)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.