In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "what is the difference between single quotation marks and double quotation marks in Shell script strings". In the operation of actual cases, many people will encounter such a dilemma, 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!
1. Basic knowledge of string
Strings are the most commonly used and useful data types in shell programming (apart from numbers and strings, there are no other types to use), strings can be in single quotation marks, double quotation marks, or without quotation marks. The difference between single and double quotation marks is similar to that of PHP.
Single quotation mark
The code is as follows:
Str='this is a string'
Restrictions on single quote strings:
Any character in the single quote will be output as is, and the variable in the single quote string is invalid.
Single quotation marks cannot appear in a single quote string (not even after using escape characters for single quotation marks).
Double quotation marks
The code is as follows:
Your_name='qinjx'
Str= "Hello, I know your are\" $your_name\ "!\ n"
Advantages of double quotation marks:
There can be variables in double quotation marks
Escape characters can appear in double quotation marks
Second, commonly used string correlation methods
Concatenate string
The code is as follows:
Your_name= "qinjx"
Greeting= "hello,"$your_name"!
Greeting_1= "hello, ${your_name}!"
Echo $greeting $greeting_1
Get string length
The code is as follows:
String= "abcd"
Echo ${# string} # output 4
Extract substring
The code is as follows:
String= "alibaba is a great company"
Echo ${string:1:4} # output liba
Look for substrings
The code is as follows:
String= "alibaba is a great company"
Echo `expr index "$string" is`
This is the end of the content of "what is the difference between single quotes and double quotes in Shell script strings". 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.