In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to use the Shell string method". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
A String is a combination of a series of characters. Strings are one of the most commonly used data types in Shell programming (there are no other types except numbers and strings).
Single quotation mark Shell string learningstr='this is a string'
Restrictions on single quote strings:
Any character in a single quote is output as is, and variables in a single quote string are invalid; a single quote cannot appear in a single quote string (not even after using escape characters for single quotation marks), but it can appear in pairs. used as a string concatenation.
Double quotation marks Shell string learningyour_name='runoob'str= "Hello, I know you are\" $your_name\ "!\ n" echo-e $str
The output is as follows:
Shell string learningHello, I know you are "runoob"!
Advantages of double quotation marks:
There can be variables in double quotes. Escape characters can appear in double quotes.
Concatenate the string Shell string learningyour_name= "runoob"
# concatenate with double quotation marks
Shell string learninggreeting= "hello,"$your_name"! "greeting_1=" hello, ${your_name}! "echo $greeting $greeting_1
# concatenate with single quotation marks
Shell string learninggreeting_2='hello,'$your_name'! 'greeting_3='hello, ${your_name}!' echo $greeting_2 $greeting_3
The output is as follows:
Shell string learninghello, runoob! Hello, runoob! hello, runoob! Hello, ${your_name}! Get string length Shell string learningstring= "abcd" echo ${# string} # output 4 extract substring
The following example intercepts 4 characters starting with the second character of the string:
Shell string learningstring= "runoob is a great site" echo ${string:1:4} # output unoo lookup substring
Find the position of the character I or o (calculate which letter appears first):
Shell string learningstring= "runoob is a great site" echo `expr index "$string" io` # output 4
Note: in the above script,'is a back quotation mark, not a single quote', don't read it wrong.
This is the end of "how to use the Shell string method". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.