当前位置:网站首页>Shell script - string
Shell script - string
2022-07-01 08:47:00 【Little snail's way】
character string (String) It is a combination of a series of characters . The string is Shell One of the most commonly used data types in programming ( Besides numbers and strings , There are no other types ).
Strings can be made of single quotes ' ' Surround , You can also use double quotes " " Surround , You can also use no quotes .
String example
str1=jack
str2="rose"
str3='100'
The difference between the three forms
- By single quotes
' 'Surrounded string :
- Any character will be output as it is , Using variables in it is not valid .
- Single quotation marks... Cannot appear in a string , Even if you escape single quotation marks .
- By double quotation marks
" "Surrounded string :
- If it contains a variable , Then the variable will be resolved ( Get the value of the variable ), Instead of outputting it as it is .
- Double quotation marks can appear in the string , As long as it is escaped .
- A string that is not surrounded by quotation marks
- Variables in strings that are not surrounded by quotation marks are also parsed , This point and double quotation marks
" "The surrounding string is the same . - No spaces in the string , Otherwise, the string after the space will be parsed as other variables or commands .
Script
#!/bin/bash
name=jack
str1= My name is $name
str2=" There's a personal \" name \" It's called $name"
str3=' My friend's name is $name'
echo $str1
echo $str2
echo $str3
Output :
My name is jack
There's a personal " name " It's called jack
My friend's name is $name
str1 It contains $name, It is resolved to a variable name References to .
str2 Contains quotation marks , But it was escaped ( By backslash \ The beginning indicates the escape character ).str2 It also includes $name, It is also resolved as a variable name References to .
str3 It also includes $name, But only as ordinary characters , Does not resolve to a variable name References to .
Get string length
The specific method is as follows ,${#string_name},string_name Represents the string name .
The code is as follows :
#!/bin/bash
name=jack
echo ${#name}
Output :
4
边栏推荐
- 挖财打新股安全吗
- 15Mo3 German standard steel plate 15Mo3 chemical composition 15Mo3 mechanical property analysis of Wuyang Steel Works
- ARM v7的体系结构A、R、M区别,分别应用在什么领域?
- It is designed with high bandwidth, which is almost processed into an open circuit?
- Foundation: 2 The essence of image
- 中考体育项目满分标准(深圳、安徽、湖北)
- Share 7 books I read in the first half of 2022
- Nacos - 服务发现
- Nacos - 配置管理
- Nacos - Configuration Management
猜你喜欢

Personal decoration notes

明明设计的是高带宽,差点加工成开路?

1. Connection between Jetson and camera

Glitch free clock switching technology

性能提升2-3倍!百度智能云第二代昆仑芯服务器上线

Qt的模型与视图

Computer tips

如何做好固定资产管理?易点易动提供智能化方案

What are the differences between the architecture a, R and m of arm V7, and in which fields are they applied?

"Analysis of 43 cases of MATLAB neural network": Chapter 30 design of combined classifier based on random forest idea - breast cancer diagnosis
随机推荐
基础:3.opencv快速入门图像和视频
Yolov3, 4, 5 and 6 Summary of target detection
ARM v7的体系结构A、R、M区别,分别应用在什么领域?
15Mo3 German standard steel plate 15Mo3 chemical composition 15Mo3 mechanical property analysis of Wuyang Steel Works
Properties of 15MnNiNbDR low temperature vessel steel, Wugang 15MnNiDR and 15MnNiNbDR steel plates
电视机尺寸与观看距离
What is 1cr0.5mo (H) material? 1cr0.5mo (H) tensile yield strength
What is the material of 16mo3 steel plate? What is the difference between 16mo3 and Q345R?
Li Kou 1358 -- number of substrings containing all three characters (double pointer)
为什么LTD独立站就是Web3.0网站!
Nacos - Configuration Management
分享2022上半年我读过的7本书
安装Oracle EE
Shell脚本-select in循环
《微机原理》——微处理器内部及外部结构
Matlab [functions and images]
Shell脚本-字符串
又到年中,固定资产管理该何去何从?
LogBack
Personal decoration notes